/* =========================================================
   القرآن الكريم — قارئ إلكتروني
   Design system: قاعدة ألوان مستوحاة من الفن الإسلامي
   (زمردي داكن + ذهبي) مع طباعة عربية مزدوجة:
   Amiri Quran للنص القرآني، Tajawal لواجهة الاستخدام.
   ========================================================= */

:root{
  color-scheme: light;

  /* ألوان الهوية */
  --primary-h: 165;
  --primary: #0f6b57;
  --primary-strong: #0b5647;
  --primary-soft: #e3f1ec;
  --gold: #b6862f;
  --gold-soft: #f6ecd8;

  /* أسطح ونصوص (فاتح) */
  --bg: #f7f6f1;
  --bg-elevated: #ffffff;
  --bg-sunken: #efede4;
  --surface-hover: #eef2ee;
  --text: #1b2420;
  --text-muted: #5e6b63;
  --text-faint: #8b968f;
  --border: #e2ded0;
  --border-strong: #cfcabb;
  --shadow-color: 150 60% 10%;

  --focus-ring: #1c7d64;

  /* الطباعة */
  --font-ui: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  --font-quran: 'Amiri Quran', 'Traditional Arabic', serif;

  --ayah-size: 1.85rem;
  --ayah-line: 2.6;

  /* مقاييس */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-round: 999px;

  --topbar-h: 64px;
  --sidebar-w: 320px;

  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

:root[data-theme="dark"]{
  color-scheme: dark;
  --primary: #35b696;
  --primary-strong: #4fd0af;
  --primary-soft: #12312b;
  --gold: #d8ac5c;
  --gold-soft: #2a2315;

  --bg: #0c1512;
  --bg-elevated: #121e19;
  --bg-sunken: #0a100e;
  --surface-hover: #17251f;
  --text: #eef3f0;
  --text-muted: #a3b3ac;
  --text-faint: #6e7d76;
  --border: #223029;
  --border-strong: #2c3d34;
  --shadow-color: 150 60% 2%;

  --focus-ring: #4fd0af;
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]):not([data-theme="dark"]){
    color-scheme: dark;
    --primary: #35b696;
    --primary-strong: #4fd0af;
    --primary-soft: #12312b;
    --gold: #d8ac5c;
    --gold-soft: #2a2315;
    --bg: #0c1512;
    --bg-elevated: #121e19;
    --bg-sunken: #0a100e;
    --surface-hover: #17251f;
    --text: #eef3f0;
    --text-muted: #a3b3ac;
    --text-faint: #6e7d76;
    --border: #223029;
    --border-strong: #2c3d34;
    --focus-ring: #4fd0af;
  }
}

/* ===================== Reset أساسي ===================== */
*, *::before, *::after{ box-sizing: border-box; }
html, body{ height: 100%; }
html{ overflow-x: hidden; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--transition), color var(--transition);
}
/* يضمن عمل خاصية hidden دائمًا حتى مع عناصر تُعرَّف لها display صريحة
   (مثل .state-panel و .settings-panel التي تستخدمان display:flex) */
[hidden]{ display: none !important; }

img{ max-width: 100%; display: block; }
button{ font: inherit; color: inherit; }
input, select{ font: inherit; color: inherit; }
ol, ul{ margin: 0; padding: 0; list-style: none; }
h1,h2,h3,p{ margin: 0; }
a{ color: inherit; }

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible{
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.skip-link{
  position: fixed;
  top: -100px;
  right: 12px;
  z-index: 1000;
  background: var(--primary);
  color: #fff;
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  transition: top var(--transition);
}
.skip-link:focus{ top: 12px; }

/* ===================== أزرار عامة ===================== */
.btn{
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  border: 1px solid transparent;
  border-radius: var(--radius-round);
  padding: .55rem 1.1rem;
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:active{ transform: scale(.97); }
.btn--primary{
  background: var(--primary);
  color: #fff;
}
.btn--primary:hover{ background: var(--primary-strong); }
.btn--ghost{
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover{ background: var(--surface-hover); }
.btn--square{ padding: .5rem; width: 2.1rem; height: 2.1rem; justify-content: center; }
.btn--play svg{ width: 18px; height: 18px; }

.icon-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-round);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
  flex: none;
}
.icon-btn:hover{ background: var(--surface-hover); }
.icon-btn--lg{ width: 52px; height: 52px; background: var(--primary); color: #fff; }
.icon-btn--lg:hover{ background: var(--primary-strong); }
.icon-btn[aria-pressed="true"]{ color: var(--primary); background: var(--primary-soft); }

/* ===================== Topbar ===================== */
.topbar{
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner{
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding-inline: 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.topbar__menu{ display: inline-flex; }

.brand{
  display: flex;
  align-items: center;
  gap: .55rem;
  text-decoration: none;
  flex: none;
}
.brand__circle{ fill: var(--primary); }
.brand__moon{ fill: var(--gold); }
.brand__text{
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.brand__text strong{
  font-weight: 900;
  color: var(--primary);
  margin-inline-start: .3rem;
}

.topbar__search{
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 480px;
  margin-inline-start: .5rem;
}
.topbar__search-icon{
  position: absolute;
  inset-inline-start: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.topbar__search input{
  width: 100%;
  min-width: 0;
  height: 42px;
  border-radius: var(--radius-round);
  border: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  color: var(--text);
  padding-inline-start: 2.6rem;
  padding-inline-end: 1rem;
  transition: border-color var(--transition), background-color var(--transition);
}
.topbar__search input::placeholder{ color: var(--text-faint); }
.topbar__search input:focus{
  outline: none;
  border-color: var(--primary);
  background: var(--bg-elevated);
}

.search-results{
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 8px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 40px -12px hsl(var(--shadow-color) / .35);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 70;
  padding: .4rem;
}
.search-results__item{
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.search-results__item:hover,
.search-results__item[aria-selected="true"]{ background: var(--surface-hover); }
.search-results__num{
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  color: var(--text-muted);
}
.search-results__name{ font-weight: 700; }
.search-results__meta{ color: var(--text-faint); font-size: .8rem; margin-inline-start: auto; }
.search-results__empty{ padding: 1rem; color: var(--text-faint); text-align: center; font-size: .9rem; }

.topbar__actions{
  display: flex;
  align-items: center;
  gap: .25rem;
  flex: none;
}
.icon-sun, .icon-moon{ transition: opacity var(--transition); }

/* ===================== Shell / Sidebar ===================== */
.shell{
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar{
  flex: none;
  width: var(--sidebar-w);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-inline-start: 1px solid var(--border);
  background: var(--bg-elevated);
  scrollbar-gutter: stable;
}
.sidebar__head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem .5rem;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 2;
}
.sidebar__head h2{ font-size: 1rem; color: var(--text-muted); }
.sidebar__close{ display: inline-flex; }

/* السماح بإخفاء/إظهار الفهرس على الشاشات الكبيرة (سطح المكتب) عبر زر القائمة
   أو زر الإغلاق داخل الفهرس نفسه، بدل بقائه ظاهرًا دائمًا بلا إمكانية إغلاق. */
@media (min-width: 861px){
  .sidebar{
    transition: width var(--transition), opacity var(--transition), border-color var(--transition);
  }
  .shell.sidebar-collapsed .sidebar{
    width: 0;
    min-width: 0;
    opacity: 0;
    overflow: hidden;
    border-inline-start-color: transparent;
    pointer-events: none;
  }
}

.surah-list{ padding: .4rem .7rem 2rem; }
.surah-item{
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .65rem .6rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition);
}
.surah-item:hover{ background: var(--surface-hover); }
.surah-item[aria-current="true"]{
  background: var(--primary-soft);
}
.surah-item[aria-current="true"] .surah-item__num{
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.surah-item[aria-current="true"] .surah-item__name{ color: var(--primary-strong); }

.surah-item__num{
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.surah-item__info{ min-width: 0; flex: 1; }
.surah-item__name{
  font-weight: 700;
  font-size: .98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.surah-item__sub{
  color: var(--text-faint);
  font-size: .76rem;
  margin-top: 1px;
}
.sidebar-overlay{
  position: fixed;
  inset: 0;
  background: hsl(150 40% 5% / .5);
  z-index: 91;
}

.sidebar__footer{
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .8rem 1.1rem;
  margin-top: .5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-faint);
  font-size: .78rem;
}
.sidebar__footer svg{ flex: none; color: var(--primary); }
.sidebar__footer strong{
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===================== المحتوى الرئيسي ===================== */
.content{
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.75rem 2rem 6rem;
}
.content:focus{ outline: none; }

.state-panel{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--text-muted);
  text-align: center;
}
.state-panel--error{ color: #b3432f; }
[data-theme="dark"] .state-panel--error{ color: #ff8a70; }

.spinner{
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

/* رأس السورة */
.surah-header{
  text-align: center;
  padding: 1.25rem 1rem 2rem;
  border-bottom: 1px dashed var(--border-strong);
  margin-bottom: 1.5rem;
}
.surah-header__nav{
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: 1.5rem;
}
.surah-header__nav .btn span{ display: inline; }
.surah-header__title{
  font-family: var(--font-quran);
  font-size: clamp(2.1rem, 4vw, 3rem);
  color: var(--primary-strong);
  font-weight: 400;
}
.surah-header__meta{
  margin-top: .5rem;
  color: var(--text-muted);
  font-size: .95rem;
}
.bismillah{
  font-family: var(--font-quran);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  color: var(--text);
  margin: 1.75rem 0 .5rem;
}
.bismillah:empty{ display: none; }

.surah-header__controls{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.reciter-select select{
  height: 2.6rem;
  border-radius: var(--radius-round);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  padding-inline: 1rem;
  cursor: pointer;
}

/* قائمة الآيات */
.verses-list{
  max-width: 880px;
  margin: 0 auto;
}
.verse{
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.25rem .5rem;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: calc(var(--topbar-h) + 16px);
  transition: background-color var(--transition);
  border-radius: var(--radius-md);
}
.verse:last-child{ border-bottom: none; }
.verse.is-playing{
  background: var(--primary-soft);
}

.verse__num{
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: .85rem;
  margin-top: .3rem;
}
.verse.is-playing .verse__num{
  background: var(--gold);
  color: #fff;
}

.verse__body{ flex: 1; min-width: 0; }
.verse__text{
  font-family: var(--font-quran);
  font-size: var(--ayah-size);
  line-height: var(--ayah-line);
  text-align: justify;
  text-align-last: right;
  color: var(--text);
}
.verse__actions{
  display: flex;
  gap: .3rem;
  margin-top: .6rem;
}
.verse__actions .icon-btn{ width: 34px; height: 34px; color: var(--text-faint); }
.verse__actions .icon-btn:hover{ color: var(--primary); }
.verse__actions .icon-btn[aria-pressed="true"]{ color: var(--gold); background: var(--gold-soft); }

.verse-skeleton{
  height: 90px;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--surface-hover) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer{
  0%{ background-position: 100% 50%; }
  100%{ background-position: 0 50%; }
}

/* ===================== مشغل الصوت السفلي ===================== */
.player-bar{
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 90;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px -14px hsl(var(--shadow-color) / .4);
  padding-bottom: env(safe-area-inset-bottom);
}
.player-bar__progress{ padding: .35rem .9rem 0; }
.player-bar__progress input[type="range"]{
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}
.player-bar__row{
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .5rem 1rem .7rem;
  max-width: 1100px;
  margin: 0 auto;
}
.player-bar__info{
  flex: 1 1 140px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.player-bar__info strong{ font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar__reciter{ color: var(--text-faint); font-size: .78rem; }
.player-bar__controls{
  display: flex;
  align-items: center;
  gap: .35rem;
  flex: none;
}
.player-bar__extra{
  display: flex;
  align-items: center;
  gap: .1rem;
  flex: 1 1 100px;
  justify-content: flex-end;
}

/* ===================== لوحة الإعدادات ===================== */
.settings-panel{
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(380px, 100vw);
  background: var(--bg-elevated);
  border-inline-start: 1px solid var(--border);
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem;
  overflow-y: auto;
  box-shadow: -20px 0 50px -20px hsl(var(--shadow-color) / .4);
  transform: translateX(0);
  animation: slideIn var(--transition) ease;
}
html[dir="rtl"] .settings-panel{ transform: translateX(0); }
@keyframes slideIn{ from{ opacity: 0; transform: translateX(12%); } to{ opacity: 1; transform: translateX(0); } }

.settings-panel__head{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-panel__head h2{ font-size: 1.1rem; }
.settings-group h3{ font-size: .85rem; color: var(--text-muted); margin-bottom: .7rem; font-weight: 700; }

.font-size-control{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg-sunken);
  border-radius: var(--radius-round);
  padding: .5rem 1rem;
}
.font-size-control__label{ min-width: 4.5rem; text-align: center; font-weight: 700; }

.segmented{
  display: flex;
  background: var(--bg-sunken);
  border-radius: var(--radius-round);
  padding: 4px;
  gap: 2px;
}
.segmented__btn{
  flex: 1;
  border: none;
  background: transparent;
  padding: .55rem .5rem;
  border-radius: var(--radius-round);
  cursor: pointer;
  font-weight: 700;
  font-size: .85rem;
  color: var(--text-muted);
  transition: background-color var(--transition), color var(--transition);
}
.segmented__btn[aria-checked="true"]{
  background: var(--primary);
  color: #fff;
}

#reciterSelect2{
  width: 100%;
  height: 2.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  color: var(--text);
  padding-inline: .8rem;
}

.settings-panel__note{
  margin-top: auto;
  font-size: .78rem;
  color: var(--text-faint);
  line-height: 1.7;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

/* ===================== Toast ===================== */
.toast{
  position: fixed;
  bottom: 90px;
  inset-inline: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 120;
}
.toast:not(:empty)::before{
  content: attr(data-msg);
  background: hsl(150 20% 12% / .92);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius-round);
  font-size: .85rem;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
}

/* ===================== Responsive ===================== */
@media (max-width: 1024px){
  :root{ --sidebar-w: 300px; }
  .content{ padding-inline: 1.25rem; }
}

@media (max-width: 860px){
  .brand__text{ display: none; }
  .topbar__search{ margin-inline-start: 0; }

  .sidebar{
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    inset-inline-end: auto;
    height: 100dvh;
    width: min(320px, 86vw);
    max-width: 100vw;
    opacity: 1;
    transform: translateX(110%);
    transition: transform var(--transition);
    z-index: 92;
    box-shadow: -18px 0 40px -18px hsl(var(--shadow-color) / .5);
  }
  .sidebar.is-open{ transform: translateX(0); }

  .surah-header__nav .btn span{ display: none; }
  .surah-header__nav .btn{ padding: .55rem .7rem; }

  .verse{ padding: 1rem .25rem; gap: .7rem; }
  .verse__num{ width: 34px; height: 34px; font-size: .75rem; }

  .content{ padding: 1.25rem .9rem 6rem; }
}

@media (max-width: 520px){
  .topbar__inner{ gap: .4rem; padding-inline: .6rem; }
  .player-bar__info strong{ font-size: .82rem; }
  .settings-panel{ width: 100vw; }
}

/* شريط تمرير أنيق */
.sidebar::-webkit-scrollbar, .settings-panel::-webkit-scrollbar{ width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .settings-panel::-webkit-scrollbar-thumb{
  background: var(--border-strong);
  border-radius: 8px;
}
