/* ===== الثيم الافتراضي (الداكن) ===== */
:root {
  --bg: #060c09;
  --bg-2: #0a1410;
  --card: rgba(255, 255, 255, .045);
  --card-2: rgba(255, 255, 255, .075);
  --card-border: rgba(255, 255, 255, .09);
  --surface: rgba(0, 0, 0, .22);
  --surface-2: rgba(0, 0, 0, .3);
  --hover: rgba(255, 255, 255, .07);
  --input-bg: rgba(0, 0, 0, .25);
  --option-bg: #0d1a14;
  --text: #eef4ef;
  --muted: #9db3a7;
  --title: #ffffff;
  --brand: #1f8566;
  --brand-2: #2dd4bf;
  --accent: #d4af37;
  --on-grad: #04130e;
  --danger: #ff8aa8;
  --danger-bg: rgba(255, 138, 168, .14);
  --gold-soft: rgba(212, 175, 55, .14);
  --grad: linear-gradient(120deg, #186b52 0%, #2dd4bf 55%, #d4af37 100%);
  --grad-text: linear-gradient(120deg, #186b52 0%, #2dd4bf 55%, #d4af37 100%);
  --shadow: 0 30px 70px -32px rgba(0, 0, 0, .8);
  --focus: rgba(45, 212, 191, .18);
  --bar-empty: rgba(255, 255, 255, .10);
  --glow-1: rgba(31, 133, 102, .30);
  --glow-2: rgba(45, 212, 191, .18);
  --glow-3: rgba(212, 175, 55, .14);
  --grid-line: rgba(255, 255, 255, .025);
  --selection: rgba(45, 212, 238, .32);
  --scrollbar: rgba(255, 255, 255, .14);
  --header-bg: rgba(6, 12, 9, .72);
  --header-border: rgba(255, 255, 255, .07);
  --viewer-bg: rgba(0, 0, 0, .35);
  --loading-bg: rgba(6, 12, 9, .9);
  --modal-bg: rgba(3, 8, 6, .72);
  --canvas-shadow: 0 10px 34px rgba(0, 0, 0, .55);
  --radius: 20px;
  /* أسماء قديمة مستخدمة في الكود */
  --ink: var(--text);
  --ink-soft: var(--muted);
  --line: var(--card-border);
  --gold: var(--accent);
}

/* ===== الثيم الفاتح ===== */
[data-theme="light"] {
  --bg: #f6f4ec;
  --bg-2: #eceade;
  --card: rgba(255, 255, 255, .72);
  --card-2: rgba(255, 255, 255, .9);
  --card-border: rgba(12, 59, 48, .13);
  --surface: rgba(255, 255, 255, .6);
  --surface-2: #ffffff;
  --hover: rgba(18, 80, 63, .075);
  --input-bg: #ffffff;
  --option-bg: #ffffff;
  --text: #1c2b26;
  --muted: #5a6b64;
  --title: #0c3b30;
  --brand: #186b52;
  --brand-2: #0f766e;
  --accent: #a8821f;
  --on-grad: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --gold-soft: rgba(212, 175, 55, .22);
  --grad: linear-gradient(135deg, #12503f, #186b52);
  --grad-text: linear-gradient(120deg, #0c3b30, #186b52 55%, #a8821f);
  --shadow: 0 20px 46px -26px rgba(12, 59, 48, .3);
  --focus: rgba(31, 133, 102, .18);
  --bar-empty: rgba(12, 59, 48, .09);
  --glow-1: rgba(31, 133, 102, .12);
  --glow-2: rgba(34, 211, 238, .10);
  --glow-3: rgba(201, 162, 39, .14);
  --grid-line: rgba(12, 59, 48, .045);
  --selection: rgba(31, 133, 102, .24);
  --scrollbar: rgba(12, 59, 48, .18);
  --header-bg: rgba(246, 244, 236, .82);
  --header-border: rgba(12, 59, 48, .1);
  --viewer-bg: rgba(255, 255, 255, .6);
  --loading-bg: rgba(246, 244, 236, .92);
  --modal-bg: rgba(12, 40, 32, .38);
  --canvas-shadow: 0 8px 26px rgba(12, 59, 48, .25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== الأيقونات ===== */
.ic-svg { width: 18px; height: 18px; flex: none; display: block; }
.tab-ico .ic-svg { width: 16px; height: 16px; }
.theme-toggle .ic-svg { width: 19px; height: 19px; }
.icon-btn .ic-svg { width: 17px; height: 17px; }
.fs-ico .ic-svg { width: 16px; height: 16px; }
.habit-ico .ic-svg { width: 26px; height: 26px; }
.date-ico .ic-svg { width: 22px; height: 22px; }
.btn-ico .ic-svg { width: 17px; height: 17px; }
.btn-delete .ic-svg { width: 15px; height: 15px; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', 'Noto Naskh Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .35s ease, color .35s ease;
}

::selection { background: var(--selection); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ===== خلفية متوهّجة ===== */
.bg-fx { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.bg-fx::before {
  content: ""; position: absolute; inset: -20%;
  background:
    radial-gradient(38% 45% at 15% 8%, var(--glow-1), transparent 60%),
    radial-gradient(35% 40% at 85% 12%, var(--glow-2), transparent 60%),
    radial-gradient(45% 45% at 50% 100%, var(--glow-3), transparent 60%);
  filter: blur(10px);
  animation: drift 22s ease-in-out infinite alternate;
}
.bg-fx::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
}
@keyframes drift { to { transform: translate3d(0, -4%, 2%) scale(1.08); } }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(14px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
}
.header-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  height: 48px;
  width: auto;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5));
  border-radius: 12px;
}
.brand-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 1px;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
  background: var(--card-2);
  color: var(--muted);
  border: 1px solid var(--card-border);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: all .22s cubic-bezier(.2, .8, .2, 1);
}
.tab-btn:hover { background: var(--hover); color: var(--title); transform: translateY(-2px); }
.tab-btn.active {
  background: var(--grad);
  color: var(--on-grad);
  border-color: transparent;
  font-weight: 800;
  box-shadow: 0 12px 26px -12px rgba(45, 212, 191, .65);
}
.tab-ico { margin-left: 6px; display: inline-flex; align-items: center; }
.listen-tab { padding: 7px 12px; }
.listen-tab .tab-ico { margin-left: 0; }

/* مفتاح تبديل الثيم */
.theme-toggle {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card-2);
  color: var(--accent);
  font-size: 19px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: all .25s cubic-bezier(.2, .8, .2, 1);
  overflow: hidden;
}
.theme-toggle:hover { transform: translateY(-2px) rotate(15deg); box-shadow: 0 10px 22px -10px rgba(0, 0, 0, .5); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

/* ===== Layout ===== */
.container { max-width: 100%; margin: 10px auto 14px; position: relative; }
.container.transitioning { overflow: hidden; }
.tab-panel { display: none; padding: 0 12px; }
.tab-panel.active { display: block; animation: panelIn .34s cubic-bezier(.2, .8, .2, 1); }
.tab-panel.leaving {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  animation: panelOut .28s cubic-bezier(.4, .6, .4, 1) forwards;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@keyframes panelOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px) scale(.985); }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 18px;
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}
.card-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--title);
  margin-bottom: 14px;
  padding-right: 12px;
  border-right: 4px solid var(--accent);
}

/* ===== Mushaf ===== */
.mushaf-layout { display: flex; gap: 16px; align-items: flex-start; }
.mushaf-main { flex: 1 1 auto; min-width: 0; }

.surah-panel {
  width: 300px; flex: none;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky; top: 84px;
  max-height: calc(100vh - 104px);
  display: flex; flex-direction: column;
  overflow: hidden;
  padding: 0;
  margin-bottom: 0;
  backdrop-filter: blur(10px);
}
.surah-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--card-border);
}
.surah-panel-title {
  font-size: 16px; font-weight: 900; color: var(--title);
  padding-right: 10px; border-right: 4px solid var(--accent);
}
.surah-close { display: none; }
.surah-search {
  margin: 12px 14px;
  padding: 9px 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.surah-search::placeholder { color: var(--muted); opacity: .6; }
.surah-search:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus); }
.surah-list { overflow-y: auto; padding: 8px; flex: 1; min-height: 120px; }
.surah-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px;
  border: none; background: transparent;
  border-radius: 10px;
  font-family: inherit;
  text-align: right;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.surah-item:hover { background: var(--hover); }
.surah-item.active {
  background: var(--grad);
  color: var(--on-grad);
  box-shadow: 0 6px 18px -8px rgba(45, 212, 191, .7);
}
.surah-num {
  width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  background: var(--card-2);
  color: var(--brand-2);
  border: 1px solid var(--card-border);
}
.surah-item.active .surah-num {
  background: color-mix(in srgb, var(--on-grad) 25%, transparent);
  color: var(--on-grad);
  border-color: color-mix(in srgb, var(--on-grad) 45%, transparent);
}
.surah-name { flex: 1; font-size: 15px; font-weight: 600; }
.surah-page { font-size: 11px; color: var(--muted); white-space: nowrap; }
.surah-item.active .surah-page { color: color-mix(in srgb, var(--on-grad) 75%, transparent); }
.surah-empty { text-align: center; color: var(--muted); padding: 18px; font-size: 13px; }

.mushaf-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 14px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  backdrop-filter: blur(10px);
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-group.grow { flex: 1; min-width: 0; }
.surah-toggle-btn { display: none; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.icon-btn {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--card-border);
  width: 38px; height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
  display: grid; place-items: center;
  transition: all .18s cubic-bezier(.2, .8, .2, 1);
}
.icon-btn:hover { background: var(--hover); color: var(--brand-2); border-color: var(--brand-2); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0) scale(.94); }
.icon-btn.round { border-radius: 50%; width: 42px; height: 42px; font-size: 15px; }
.page-input {
  width: 78px;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.page-input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus); }
.page-of { font-size: 13px; color: var(--muted); }
.select {
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  max-width: 100%;
  font-family: inherit;
}
.select option { background: var(--option-bg); color: var(--text); }
.mushaf-status { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }

.status-chip {
  background: var(--grad);
  color: var(--on-grad);
  font-size: 13px;
  font-weight: 800;
  padding: 5px 14px;
  border-radius: 999px;
}
.status-chip.muted {
  background: var(--card-2);
  color: var(--muted);
  border: 1px solid var(--card-border);
  font-weight: 600;
}

/* ===== عرض عريض موحّد لكل التبويبات: حواف أضيق ومحتوى أكبر ===== */
.pdf-viewer {
  background: var(--viewer-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: calc(100vh - 208px);
  min-height: 420px;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 10px;
  position: relative;
  backdrop-filter: blur(8px);
}
.pdf-pages {
  display: flex;
  justify-content: center;
  justify-content: safe center;
  align-items: flex-start;
  position: relative;
}
.pdf-layer {
  display: flex;
  align-items: flex-start;
  /* مطابقة توسيط الطبقة الظاهرة: حتى الطبقة المغادرة (المطلقة)
     تحافظ على وضع المحتوى فلا يقفز جانباً عند بدء الانزلاق */
  justify-content: center;
  justify-content: safe center;
  gap: 12px;
  direction: rtl;
  position: relative; /* ليعمل z-index ومقص المنظور */
  perspective: 1800px;
  z-index: 2;         /* الطبقة الجديدة فوق الطبقة المغادرة دائماً */
  will-change: opacity;
  animation: layerIn .3s cubic-bezier(.22, .61, .36, 1);
}
.pdf-layer.flip-next, .pdf-layer.flip-prev { animation: none; }
.pdf-layer.leaving {
  position: absolute;
  inset: 0;
  z-index: 1; /* تبقى أسفل الطبقة الجديدة */
  pointer-events: none;
  /* لا تتلاشى: تبقى مرئية بكامل عتامتها حتى يكتمل ظهور الجديدة فوقها،
     فلا يظهر لون الخلفية أبداً أثناء الانتقال (لا تعتيم ولا وميض)؛
     تُزال فور إكتمال الجديدة */
  animation: none;
}
/* ====== انقلاب الصفحة حول الكعب (مثل المصحف الالكتروني) ====== */
.flip-page {
  position: absolute;
  top: 0;
  z-index: 3;
  transform-style: preserve-3d;
  will-change: transform;
}
.pdf-layer.flip-next .flip-page {
  left: 0;
  transform-origin: right center; /* الكعب في وسط الفتح */
  animation: flipNext .42s cubic-bezier(.25, .8, .3, 1) forwards;
}
.pdf-layer.flip-prev .flip-page {
  right: 0;
  transform-origin: left center; /* الكعب في وسط الفتح */
  animation: flipPrev .42s cubic-bezier(.25, .8, .3, 1) forwards;
}
.flip-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-face canvas { display: block; width: 100%; height: 100%; }
.flip-face.back { transform: rotateY(180deg); }
.flip-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .22));
  opacity: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.pdf-layer.flip-next .flip-page::after {
  background: linear-gradient(90deg, rgba(0, 0, 0, .22), rgba(0, 0, 0, 0));
  animation: flipSheen .42s cubic-bezier(.25, .8, .3, 1) forwards;
}
.pdf-layer.flip-prev .flip-page::after {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .22));
  animation: flipSheen .42s cubic-bezier(.25, .8, .3, 1) forwards;
}
@keyframes flipNext { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } }
@keyframes flipPrev { from { transform: rotateY(0deg); } to { transform: rotateY(-180deg); } }
@keyframes flipSheen { 0% { opacity: 0; } 45% { opacity: 1; } 100% { opacity: 0; } }
@keyframes layerIn { from { opacity: 0; } to { opacity: 1; } }
.pdf-pages .pdf-page {
  display: block;
  user-select: none;
  box-shadow: var(--canvas-shadow);
  border-radius: 4px;
  background: #fff;
  flex: none;
}
.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--brand-2);
  background: var(--loading-bg);
  z-index: 5;
  transition: opacity .32s ease;
}
.viewer-loading[hidden] { display: none; }
.spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--card-border);
  border-top-color: var(--brand-2);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Tracker ===== */
.date-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
}
.date-ico { display: inline-flex; align-items: center; color: var(--accent); }
.date-display { flex: 1; text-align: center; min-width: 180px; }
.date-greg { font-size: 18px; font-weight: 800; color: var(--title); }
.date-hijri { font-size: 13px; color: var(--muted); margin-top: 2px; }
.date-picker {
  padding: 9px 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
  color-scheme: dark;
  transition: border-color .15s, box-shadow .15s;
}
[data-theme="light"] .date-picker { color-scheme: light; }
.date-picker:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus); }

/* ===== الأزرار ===== */
.btn {
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--card-2);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .22s cubic-bezier(.2, .8, .2, 1), box-shadow .22s, background .22s, border-color .22s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { background: var(--hover); color: var(--title); transform: translateY(-2px); box-shadow: 0 12px 24px -16px rgba(0, 0, 0, .6); }
.btn:active { transform: translateY(0) scale(.97); }
.btn:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.btn.small { padding: 8px 16px; font-size: 13px; }
.btn.lg { padding: 13px 30px; font-size: 16px; font-weight: 800; }
.btn-ico { font-size: 17px; line-height: 1; }
.btn.primary {
  background: var(--grad);
  color: var(--on-grad);
  border: none;
  font-weight: 800;
  box-shadow: 0 16px 34px -14px rgba(45, 212, 191, .7);
}
.btn.primary:hover { filter: brightness(1.08); color: var(--on-grad); box-shadow: 0 22px 44px -14px rgba(45, 212, 191, .85); }
.btn.primary:active { transform: translateY(0) scale(.97); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--card-border);
}
.btn.ghost:hover { background: var(--hover); }

.friday-badge {
  background: var(--gold-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: color-mix(in srgb, var(--accent) 78%, var(--text));
  padding: 11px 16px;
  border-radius: 14px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 700;
}
.friday-badge[hidden] { display: none; }

.form-section {
  padding: 16px 0;
  border-bottom: 1px dashed var(--card-border);
}
.form-section:last-of-type { border-bottom: none; }
.form-section-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 15px;
  color: var(--title);
  margin-bottom: 14px;
  font-weight: 800;
}
.section-toggle { margin-inline-start: auto; display: inline-flex; align-items: center; cursor: pointer; }
.section-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-switch {
  width: 44px; height: 24px; flex: none;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--card-border);
  position: relative;
  transition: background .18s, border-color .18s;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  transition: transform .18s ease, background .18s ease;
}
.section-toggle input:checked + .toggle-switch { background: var(--brand); border-color: var(--brand-2); }
.section-toggle input:checked + .toggle-switch::after { transform: translateX(-20px); background: #fff; }
.section-toggle input:focus-visible + .toggle-switch { box-shadow: 0 0 0 3px var(--focus); }

.fs-ico {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  background: color-mix(in srgb, var(--brand-2) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand-2) 32%, transparent);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brand-2);
}

/* صناديق "من ← إلى" */
.range-cards { display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap; }
.range-box {
  flex: 1 1 240px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  transition: border-color .15s, box-shadow .15s;
}
.range-box:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus); }
.range-box .select { flex: 1 1 130px; min-width: 0; }
.range-box .ayah-select { flex: 0 0 auto; width: 92px; padding: 8px 6px; text-align: center; text-align-last: center; }

/* قائمة منسدلة مخصّصة (تنفتح للأسفل دائماً) */
.dd-menu {
  position: fixed;
  z-index: 300;
  max-width: calc(100vw - 20px);
  overflow-y: auto;
  background: var(--option-bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  font-size: 14px;
  font-family: inherit;
  animation: dd-pop .14s ease-out;
}
.dd-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dd-item:hover { background: var(--hover); }
.dd-item.active { background: var(--brand); color: var(--on-grad); font-weight: 700; }
.dd-item.disabled { opacity: .45; cursor: default; }
.dd-item.disabled:hover { background: transparent; }
.select.dd-open { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus); }
@keyframes dd-pop { from { opacity: 0; transform: translateY(-6px); } }
.range-tag {
  font-size: 11px; font-weight: 800; color: var(--on-grad);
  background: var(--grad);
  border-radius: 999px;
  padding: 3px 11px;
  flex: none;
}
.ayah-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.range-arrow { color: var(--accent); font-size: 22px; align-self: center; padding: 0 2px; }
.ayah-input {
  width: 74px;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.text-input {
  flex: 1;
  min-width: 120px;
  padding: 9px 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.text-input::placeholder, .ayah-input::placeholder { color: var(--muted); opacity: .55; }
.text-input:focus, .ayah-input:focus, .select:focus, .date-picker:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--focus);
}
.range-cards.disabled {
  opacity: .4;
  pointer-events: none;
  filter: grayscale(.55);
}
.habit-cards.disabled {
  opacity: .4;
  pointer-events: none;
  filter: grayscale(.55);
}

/* بطاقات طريقة الحفظ */
.habit-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.habit-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 16px 12px;
  background: var(--surface);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  color: var(--text);
  transition: all .2s ease;
}
.habit-card:hover { border-color: var(--brand-2); transform: translateY(-3px); box-shadow: 0 10px 24px -14px rgba(0, 0, 0, .6); }
.habit-card input { position: absolute; opacity: 0; }
.habit-ico {
  color: var(--brand-2);
  filter: grayscale(.6);
  opacity: .6;
  transition: all .2s ease;
}
.habit-name { font-size: 14px; font-weight: 800; color: var(--title); }
.habit-desc { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.habit-card::after {
  content: "✓";
  position: absolute;
  top: 8px; left: 10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand-2);
  color: var(--on-grad);
  font-size: 13px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(.5);
  transition: all .2s ease;
}
.habit-card:has(input:checked) {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand-2) 16%, transparent), var(--gold-soft));
  border-color: var(--brand-2);
  box-shadow: 0 8px 24px -12px color-mix(in srgb, var(--brand-2) 60%, transparent);
}
.habit-card:has(input:checked) .habit-ico { filter: none; opacity: 1; }
.habit-card:has(input:checked)::after { opacity: 1; transform: scale(1); }

.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 6px; flex-wrap: wrap; }
.save-status { font-size: 14px; font-weight: 700; }
.save-status.ok { color: var(--brand-2); }
.save-status.err { color: var(--danger); }

/* ===== Entries ===== */
.entries-list { display: flex; flex-direction: column; gap: 10px; }
.entry {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.entry-date {
  background: var(--grad);
  color: var(--on-grad);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
  min-width: 78px;
  flex-shrink: 0;
  font-weight: 800;
}
.entry-day { font-size: 19px; font-weight: 900; line-height: 1.1; }
.entry-mon { font-size: 11px; opacity: .85; }
.entry-body { flex: 1; min-width: 200px; }
.entry-line { font-size: 14px; margin-bottom: 4px; }
.entry-line b { color: var(--brand-2); }
.entry-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag {
  background: color-mix(in srgb, var(--brand-2) 13%, transparent);
  color: var(--brand-2);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--brand-2) 30%, transparent);
}
.entry-empty {
  text-align: center;
  color: var(--muted);
  padding: 22px;
  font-size: 14px;
}
.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
}
.btn-delete:hover { background: var(--danger-bg); }

/* ===== Dashboard ===== */
.dash-topbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.base-count {
  background: var(--brand-2);
  color: var(--on-grad);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
  font-weight: 900;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.stat-card { text-align: center; }
.stat-card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--brand-2) 42%, transparent);
}
.form-card:hover, .history-card:hover {
  border-color: color-mix(in srgb, var(--brand-2) 42%, transparent);
}
/* إبراز بطلات تبويب الإحصائيات عند المرور عليها (بلا أي إزاحة) */
#tab-dashboard .card { transition: border-color .15s, box-shadow .15s; }
#tab-dashboard .card:hover {
  border-color: color-mix(in srgb, var(--brand-2) 42%, transparent);
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.stat-value {
  font-size: 34px; font-weight: 900; line-height: 1.1;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.progress-bar {
  background: var(--bar-empty);
  border-radius: 999px;
  height: 9px;
  margin-top: 12px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--grad-text);
  border-radius: 999px;
  transition: width .6s ease;
}

.habits-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.habit-stat {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface);
}
.habit-stat-name { font-size: 14px; font-weight: 700; margin-bottom: 8px; color: var(--title); }
.habit-stat-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.chart-wrap { overflow-x: auto; padding-bottom: 4px; }
.chart-svg { display: block; }
.chart-legend { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; gap: 14px; justify-content: center; }

/* ---- تقدّم المراجعة ---- */
.rev-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.rev-stat {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
}
.rev-stat b {
  display: block;
  font-size: 26px; font-weight: 900; line-height: 1.1;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rev-stat span { font-size: 11.5px; color: var(--muted); }
.rev-strip { display: flex; flex-wrap: wrap; gap: 5px; direction: rtl; }
.rev-cell {
  width: 16px; height: 16px; flex: none;
  border-radius: 5px;
  background: var(--bar-empty);
  border: 1px solid var(--card-border);
}
.rev-cell.on { background: var(--brand-2); border-color: var(--brand-2); }
.rev-cell.friday { outline: 1.5px solid var(--accent); outline-offset: -1.5px; }
.rev-legend {
  display: flex; gap: 7px; align-items: center;
  margin-top: 12px; font-size: 11.5px; color: var(--muted);
  flex-wrap: wrap;
}
.rev-last {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--card-border);
  font-size: 13.5px;
  color: var(--text);
}
.rev-last b { color: var(--brand-2); }

.journey { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.journey-item {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  text-align: center;
}
.journey-num {
  font-size: 22px; font-weight: 900;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.journey-lbl { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ===== نافذة الحفظ القديم ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .18s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(620px, 100%);
  max-height: 86vh;
  overflow: auto;
  position: relative;
  margin-bottom: 0;
  animation: modalIn .24s cubic-bezier(.22, .61, .36, 1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-close { position: absolute; top: 14px; inset-inline-end: 14px; }

.base-hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.base-empty {
  text-align: center; color: var(--muted);
  padding: 14px; font-size: 13px;
  border: 1px dashed var(--card-border);
  border-radius: 12px;
  margin-top: 12px;
}
.base-item { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.base-range {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  flex-wrap: wrap;
}
.base-range .pill {
  font-size: 11px; font-weight: 800; color: var(--on-grad);
  background: var(--grad);
  border-radius: 999px; padding: 2px 10px;
  flex: none;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
  border-top: 1px solid var(--header-border);
  margin-top: 20px;
}

/* ===== لوحة السور كدرج على الشاشات الصغيرة ===== */
@media (max-width: 1024px) {
  .surah-toggle-btn { display: inline-grid; }
  .surah-panel {
    display: none;
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(330px, 88vw);
    max-height: 100vh;
    border-radius: 0;
    z-index: 220;
    box-shadow: -12px 0 44px rgba(0, 0, 0, .6);
  }
  .surah-panel.open { display: flex; animation: slideInRight .25s ease; }
  .surah-close { display: inline-grid; }
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: none; } }

@media (max-width: 720px) {
  .header-inner { flex-direction: column; align-items: stretch; }
  .header-actions { justify-content: center; }
  .tabs { justify-content: center; }
  .brand { justify-content: center; text-align: center; }
  .mushaf-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-group { justify-content: center; }
  .range-cards { flex-direction: column; }
  .range-arrow { display: none; }
  .pdf-viewer { height: calc(100vh - 320px); }
}

/* احترام تفضيل تقليل الحركة في النظام */
@media (prefers-reduced-motion: reduce) {
  .tab-panel.active, .pdf-layer { animation: none !important; }
  .tab-panel.leaving { opacity: 0 !important; }
  .pdf-layer.leaving { display: none !important; }
}

/* ===== الاستماع ===== */
.listen-popover {
  display: flex;
  position: fixed;
  z-index: 250;
  top: 0;
  inset-inline-start: 0;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 18px 44px -16px rgba(0, 0, 0, .65);
  padding: 8px 12px;
  width: min(450px, calc(100vw - 16px));
  overflow-y: auto;
  animation: popoverIn .2s cubic-bezier(.22, .61, .36, 1);
}
.listen-popover[hidden] { display: none; }
@keyframes popoverIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
.lsn-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.lsn-label { font-size: 10px; font-weight: 800; color: var(--muted); flex: none; }
.lsn-row .select { padding: 4px 6px; font-size: 12px; max-width: 128px; }
.lsn-row .ayah-select { width: 52px; padding: 4px 2px; text-align: center; text-align-last: center; }
.lsn-row .range-arrow { font-size: 13px; padding: 0; }
.lsn-close { position: absolute; top: 4px; inset-inline-end: 4px; width: 22px; height: 22px; font-size: 10px; padding: 0; flex: none; }
.listen-popover .player { padding: 6px 8px; margin: 0; }
.listen-popover .player-now { font-size: 11px; text-align: center; }
.listen-popover .player .progress-bar { margin-top: 5px; height: 5px; }
.listen-popover .player-transport { gap: 5px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.listen-popover .player-transport .icon-btn.round { width: 26px; height: 26px; font-size: 11px; flex: none; }
.listen-popover .player-transport .btn.small { padding: 5px 10px; font-size: 11px; flex: none; }
.listen-popover .repeat-mode { flex: none; }
.listen-popover .repeat-mode-btn { padding: 4px 9px; font-size: 11px; }
.listen-popover .repeat-count { font-size: 11px; gap: 5px; flex: none; }
.listen-popover .repeat-count .ayah-input { width: 48px; padding: 4px 3px; text-align: center; }
.listen-popover .player-count { font-size: 10px; }
.listen-popover .save-status { font-size: 11px; }

.repeat-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.repeat-mode {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.repeat-mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.repeat-mode-btn:hover { color: var(--text); }
.repeat-mode-btn.active {
  background: var(--grad);
  color: var(--on-grad);
}
.repeat-count {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.repeat-count .ayah-input { width: 74px; text-align: center; }

.player {
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 16px;
}
.player-now {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}
.player .progress-bar { margin-top: 10px; }
.player-transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.player-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

/* ===== شاشة الدخول / إنشاء حساب ===== */
/* التطبيق مخفي حتى يتم الدخول وتحميل البيانات */
body.booting > :not(.bg-fx):not(#auth-screen),
body.signed-out > :not(.bg-fx):not(#auth-screen) { display: none !important; }
body:not(.booting):not(.signed-out) #auth-screen { display: none; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0;
  padding: 32px 28px 26px;
  animation: layerIn .4s ease;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
  height: 72px;
  width: auto;
  border-radius: 16px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .4));
  margin-bottom: 8px;
}
.auth-brand .brand-title { font-size: 32px; }
.auth-brand .brand-sub { font-size: 13px; }
.auth-loading { text-align: center; color: var(--muted); padding: 12px 0; }
.auth-loading .spinner { margin: 0 auto 12px; }
.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.auth-tab:hover { color: var(--title); }
.auth-tab.active { background: var(--grad); color: var(--on-grad); }
.auth-tab:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form[hidden] { display: none; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field > span { font-size: 14px; font-weight: 700; color: var(--title); }
.auth-field > small { font-size: 12px; color: var(--muted); }
.auth-field .text-input { width: 100%; padding: 11px 14px; font-size: 15px; text-align: left; }
.auth-submit { margin-top: 6px; width: 100%; justify-content: center; }
.auth-submit:disabled, .auth-form input:disabled { opacity: .6; cursor: default; }
.auth-msg { margin-top: 14px; text-align: center; min-height: 1.7em; color: var(--muted); }
.auth-msg.ok { color: var(--brand-2); }
.auth-msg.err { color: var(--danger); }

/* شارة المستخدم في الشريط العلوي */
.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 12px;
  border: 1px solid var(--card-border);
  border-radius: 99px;
  background: var(--card);
  color: var(--muted);
}
.user-chip .ic-svg { width: 16px; height: 16px; }
.user-name { font-size: 13px; font-weight: 700; color: var(--title); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .icon-btn { width: 30px; height: 30px; border-radius: 50%; }
