/* ── 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;
  --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;
  --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;
}

/* ── Header ────────────────────────────────────────────── */
.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: 900px;
  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;
}

/* ── Button base ───────────────────────────────────────── */
.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;
}

/* ── Info button & tooltip ─────────────────────────────── */
.info-btn {
  position: relative;
  background: none;
  border: none;
  padding: 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;
  opacity: 0.35;
}

.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;
  width: calc(50% - 2px);
}
[data-theme="light"] .theme-knob { left: 2px; }
[data-theme="dark"]  .theme-knob { left: 50%; }
[data-theme="light"] #theme-light,
[data-theme="dark"]  #theme-dark  { opacity: 1; color: var(--text); }

/* ── 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;
  opacity: 0.35;
}

.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;
  width: calc(50% - 2px);
}
[data-font="uthmani"] .font-knob { left: 2px; }
[data-font="indopak"] .font-knob { left: 50%; }
[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; }

/* ── Main layout ───────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: .75rem 1rem 1.5rem;
}

#panel-wrap {}

/* ── Ayah panel ────────────────────────────────────────── */
.ayah-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: background-color .25s ease, border-color .25s ease;
}

.ayah-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;
}

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

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

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

.ayah-ref {
  font-size: .85rem;
  color: var(--text-muted);
  letter-spacing: .04em;
  flex-shrink: 0;
}

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

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

/* ── Ayah body ─────────────────────────────────────────── */
.ayah-body {
  padding: 1.5rem 1.5rem 2rem;
  font-size: 1.5rem;
}

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

[data-font="uthmani"] .arabic-flow {
  font-family: "UthmanicHafs", serif;
  font-size: 1.4em;
  line-height: 2.2;
}

[data-font="uthmani"] .arabic-flow .mark-circle {
  font-family: serif;
  font-size: 0.5em;
  vertical-align: 0.9em;
}

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

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

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

/* ── Reading mode ──────────────────────────────────────── */
.reading-flow {
  text-align: justify;
  text-align-last: right;
}

/* ── Line groups ───────────────────────────────────────── */
.line-group {
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.line-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.arabic-line {
  margin-bottom: .5rem;
}

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

.transliteration-line {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  direction: ltr;
  text-align: left;
  font-size: .875rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
  margin-bottom: .35rem;
}

.translation-line {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  direction: ltr;
  text-align: left;
  font-size: .925rem;
  color: var(--text-trans);
  line-height: 1.6;
}

/* ── 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; }

  main { padding: .5rem .75rem 1.5rem; }
  .ayah-body { padding: 1rem; font-size: 1.35rem; }
}

/* ── 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;
  }
}
