/* ── Fonts ─────────────────────────────────────────────── */
@font-face {
  font-family: "UthmanicHafs";
  src: url("../fonts/UthmanicHafs1Ver18.woff2") format("woff2");
  font-display: swap;
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: "IndoPakNastaleeq";
  src: url("../fonts/indopak-nastaleeq-waqf-lazim-v4.2.1.woff2") format("woff2");
  font-display: swap;
  font-weight: normal;
  font-style: normal;
}

/* ── Design tokens ─────────────────────────────────────── */
:root[data-theme="light"] {
  --bg:          #faf8f5;
  --bg-card:     #ffffff;
  --bg-tab:      #f0ece6;
  --bg-tab-active: #ffffff;
  --toggle-knob: #ffffff;
  --border:      #e5dfd6;
  --text:        #1a1814;
  --text-muted:  #6b6359;
  --text-trans:  #4a4440;
  --accent:      #5c7a5c;
  --accent-fg:   #ffffff;
  --tab-shadow:  0 1px 3px rgba(0,0,0,.08);
  --card-shadow: 0 1px 4px rgba(0,0,0,.06);
}

:root[data-theme="dark"] {
  --bg:          #12110f;
  --bg-card:     #1c1a17;
  --bg-tab:      #232018;
  --bg-tab-active: #1c1a17;
  --toggle-knob: #3e3a32;
  --border:      #2e2b26;
  --text:        #ede8e0;
  --text-muted:  #8a8075;
  --text-trans:  #b5ada3;
  --accent:      #7aab7a;
  --accent-fg:   #0e1a0e;
  --tab-shadow:  0 1px 3px rgba(0,0,0,.3);
  --card-shadow: 0 1px 4px rgba(0,0,0,.25);
}

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  transition: background-color .25s ease, color .25s ease;
  min-height: 100vh;
}

@media (max-width: 640px) {
  body {
    height: auto;
    overflow: auto;
  }
}

/* ── Layout ────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background-color .25s ease, border-color .25s ease;
}

.header-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  gap: 1rem;
}

.title-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-shrink: 0;
}

.site-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}

.controls {
  display: flex;
  gap: .5rem;
  align-items: stretch;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tab);
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover {
  background: var(--bg-tab-active);
  color: var(--text);
  border-color: var(--text-muted);
}

.theme-toggle:hover,
.font-toggle:hover {
  background: var(--bg-tab);
  border-color: var(--border);
}

.btn input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.btn-icon {
  font-size: .95rem;
  line-height: 1;
}

/* ── Info button & tooltip ─────────────────────────────── */
.info-btn {
  position: relative;
  background: none;
  border: none;
  padding: 0;
  margin-left: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: color .2s;
}

.info-btn:hover {
  color: var(--text);
}

.info-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem .65rem;
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  z-index: 200;
  pointer-events: none;
}

.info-btn.open .info-tooltip {
  display: block;
}

/* ── Theme pill toggle ─────────────────────────────────── */
.theme-toggle {
  position: relative;
  padding: 2px;
  gap: 0;
  overflow: hidden;
  align-items: center;
}

.theme-opt {
  position: relative;
  z-index: 1;
  padding: .1rem .35rem;
  border-radius: 4px;
  transition: color .2s;
  white-space: nowrap;
}

.theme-knob {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 4px;
  background: var(--toggle-knob);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: left .2s ease;
  pointer-events: none;
}

[data-theme="light"] .theme-knob,
[data-theme="dark"]  .theme-knob { width: calc(50% - 2px); }

[data-theme="light"] .theme-knob { left: 2px; }
[data-theme="dark"]  .theme-knob { left: 50%; }

.theme-opt { opacity: 0.35; }
[data-theme="light"] #theme-light,
[data-theme="dark"]  #theme-dark  { opacity: 1; color: var(--text); }

/* main */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: .75rem 1rem;
  height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

#panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: .6rem;
  flex: 1;
  min-height: 0;
}

/* ── Surah panel ───────────────────────────────────────── */
.surah-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color .25s ease, border-color .25s ease;
  min-height: 0;
  min-width: 0;
}

.surah-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: .55rem .9rem .45rem;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
  flex-shrink: 0;
}

.surah-title-group {
  display: flex;
  align-items: baseline;
  gap: .45rem;
}

.surah-name {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
}

.surah-meaning {
  font-size: .72rem;
  color: var(--text-muted);
}

.surah-number {
  font-size: .68rem;
  color: var(--text-muted);
  letter-spacing: .04em;
  flex-shrink: 0;
}

.surah-arabic-name {
  font-family: "UthmanicHafs", serif;
  font-size: 1.05rem;
  direction: rtl;
  line-height: 1.6;
  color: var(--text);
  flex-shrink: 0;
}

.surah-bismillah {
  font-family: "UthmanicHafs", serif;
  font-size: .8rem;
  direction: rtl;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Surah body ────────────────────────────────────────── */
.surah-body {
  flex: 1;
  overflow: hidden;
  padding: .75rem .9rem .85rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.arabic {
  direction: rtl;
  text-align: right;
  color: var(--text);
}

/* Arabic sizes — em so JS can scale via surah-body font-size */
[data-font="uthmani"] .arabic {
  font-family: "UthmanicHafs", serif;
  font-size: 1.4em;
  line-height: 2.4;
}

[data-font="indopak"] .arabic {
  font-family: "IndoPakNastaleeq", serif;
  font-size: 1.55em;
  line-height: 2.8;
}

/* ── Visibility toggles ────────────────────────────────── */
[data-hide-translit="true"]  .transliteration { display: none; }
[data-hide-translation="true"] .translation   { display: none; }

.ayah-marker {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: .7em;
  color: var(--accent);
  direction: rtl;
  unicode-bidi: embed;
}

.sep-marker {
  font-size: .68em;
  color: var(--accent);
  font-style: normal;
}

.transliteration {
  font-size: .75em;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

.translation {
  font-size: .8em;
  color: var(--text-trans);
  line-height: 1.65;
}

/* ── Font pill toggle ──────────────────────────────────── */
.font-toggle {
  position: relative;
  padding: 2px;
  gap: 0;
  overflow: hidden;
  align-items: center;
}

.font-opt {
  position: relative;
  z-index: 1;
  padding: .1rem .35rem;
  border-radius: 4px;
  transition: color .2s;
  white-space: nowrap;
}

.font-knob {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 4px;
  background: var(--toggle-knob);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: left .2s ease;
  pointer-events: none;
}

[data-font="uthmani"] .font-knob,
[data-font="indopak"] .font-knob { width: calc(50% - 2px); }

[data-font="uthmani"] .font-knob { left: 2px; }
[data-font="indopak"] .font-knob { left: 50%; }

.font-opt { opacity: 0.35; }
[data-font="uthmani"] #font-uthmani,
[data-font="indopak"] #font-indopak { opacity: 1; color: var(--text); }

.font-preview {
  display: inline-block;
  direction: rtl;
  font-size: .95em;
  line-height: 1;
  height: 1em;
  overflow: hidden;
  vertical-align: middle;
}

.uthmani-preview { font-family: "UthmanicHafs", serif; }
.indopak-preview  { font-family: "IndoPakNastaleeq", serif; }


/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  body {
    height: auto;
    overflow: auto;
  }

  .site-header {
    position: static;
  }

  .header-inner {
    height: auto;
    flex-wrap: wrap;
    padding: .4rem .75rem;
    gap: .4rem;
  }

  .title-group {
    width: 100%;
    justify-content: space-between;
  }

  .controls {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .35rem;
  }

  .btn, .theme-toggle, .font-toggle {
    justify-content: center;
  }

  .theme-opt, .font-opt {
    flex: 1;
    text-align: center;
    justify-content: center;
  }

  main {
    height: auto;
    padding: .5rem .75rem 1rem;
  }

  #panels {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    gap: .5rem;
  }

  .surah-panel { height: auto; overflow: visible; }
  #surah-109 { order: 1; }
  #surah-112 { order: 2; }
  #surah-113 { order: 3; }
  #surah-114 { order: 4; }

  .surah-body {
    overflow: visible;
    flex: none;
  }
}

/* ── Other surahs footer ──────────────────────────────── */
.site-footer {
  margin-top: .5rem;
  padding: 1rem;
}

.site-links {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
}

.site-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem .4rem;
  border-radius: 6px;
  background: var(--bg-tab);
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .2s, color .2s;
  flex: 1 1 calc(50% - .25rem);
}
.site-link:hover {
  background: var(--bg-tab-active);
  color: var(--text);
}
.site-link-ar {
  font-family: "UthmanicHafs", serif;
  direction: rtl;
  font-size: 1.3em;
}

@media (min-width: 641px) {
  .site-links {
    flex-wrap: nowrap;
    gap: .25rem;
  }

  .site-link {
    padding: .75rem .6rem;
    white-space: nowrap;
    flex: 1 1 0;
  }
}
