/* Tesbihat reader.
   Layout: one narrow reading column; sticky prayer tabs with settings + PDF buttons; each prayer is a
   numbered sequence of steps, Arabic first, English under it. Neutral palettes only, no accent colors. */

/* ---------- color tokens (themes) ---------- */
:root {
  --bg: #fdfdfc; --fg: #161616; --muted: #646464; --line: #dedede; --chip: #f1f1f0;
  --surface: #ffffff; --scrim: rgba(0, 0, 0, 0.18); --shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  color-scheme: light;

  --ar-font: "Scheherazade New", "Amiri", "Noto Naskh Arabic", "Traditional Arabic", serif;
  --en-font: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ar-size: 1.85rem;
  --ar-scale: 1; --en-scale: 1; --lh-scale: 1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121212; --fg: #ececec; --muted: #a2a2a2; --line: #2e2e2e; --chip: #1f1f1f;
    --surface: #1b1b1b; --scrim: rgba(0, 0, 0, 0.45); --shadow: 0 6px 24px rgba(0, 0, 0, 0.6); color-scheme: dark;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="sepia"] {
  --bg: #f6f0e3; --fg: #2b2419; --muted: #6b604f; --line: #ddd2bc; --chip: #ece3d0;
  --surface: #fbf6ec; --scrim: rgba(43, 36, 25, 0.2); --shadow: 0 6px 24px rgba(60, 45, 20, 0.16); color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121212; --fg: #ececec; --muted: #a2a2a2; --line: #2e2e2e; --chip: #1f1f1f;
  --surface: #1b1b1b; --scrim: rgba(0, 0, 0, 0.45); --shadow: 0 6px 24px rgba(0, 0, 0, 0.6); color-scheme: dark;
}
:root[data-theme="black"] {
  --bg: #000000; --fg: #d6d6d6; --muted: #8c8c8c; --line: #242424; --chip: #121212;
  --surface: #0c0c0c; --scrim: rgba(0, 0, 0, 0.55); --shadow: 0 0 0 1px #242424; color-scheme: dark;
}

/* ---------- font choices ---------- */
:root[data-arfont="amiri"] { --ar-font: "Amiri", "Scheherazade New", "Noto Naskh Arabic", serif; }
:root[data-arfont="noto"] { --ar-font: "Noto Naskh Arabic", "Scheherazade New", "Amiri", serif; }
:root[data-enfont="sans"] { --en-font: "Source Sans 3", var(--ui-font); }
.f-scheherazade { font-family: "Scheherazade New", serif; }
.f-amiri { font-family: "Amiri", serif; }
.f-noto { font-family: "Noto Naskh Arabic", serif; }
.f-serif { font-family: "Source Serif 4", Georgia, serif; }
.f-sans { font-family: "Source Sans 3", var(--ui-font); }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--en-font); font-size: 17px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button, input, output { font: inherit; color: inherit; }
button { -webkit-appearance: none; appearance: none; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: 8px; top: -100px; z-index: 50; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-family: var(--ui-font); }
.skip:focus { top: calc(8px + env(safe-area-inset-top, 0px)); }

.wrap { max-width: 760px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

header.top { padding-block: calc(24px + env(safe-area-inset-top, 0px)) 8px; }
header.top h1 { font-size: 1.9rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
header.top h1 .ar { font-family: var(--ar-font); font-weight: 400; font-size: 2.1rem; color: var(--muted); }
header.top p { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }
.row-btn svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row-btn + .row-btn { margin-top: 8px; }
.row-btn {
  display: flex; color: inherit; text-decoration: none; align-items: center; gap: 12px; width: 100%; min-height: 56px; margin-top: 12px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: none; cursor: pointer; text-align: left; font-size: 1rem;
}
.row-btn:hover { background: var(--chip); }
.row-btn > span { flex: 1; display: grid; }
.row-btn small { color: var(--muted); font-size: 0.82rem; }

/* ---------- sticky bar ---------- */
nav.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar-row { display: flex; align-items: center; gap: 4px; padding-block: 6px; }
.tabs {
  flex: 1 1 auto; min-width: 0; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  scroll-padding-inline: 8px;
}
.tabs::-webkit-scrollbar { display: none; }
/* fade the right edge only while there are more tabs to scroll to */
.tabs.more {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.tab {
  flex: none; font-size: 0.95rem; background: none; border: 0; color: var(--muted);
  min-height: 44px; padding: 0 1px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center;
}
.tab > span { padding: 6px 11px; border-radius: 999px; }
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--bg); }
.tab[aria-selected="true"] > span { background: var(--fg); }
.tab:focus-visible { outline: none; }
.tab:focus-visible > span { outline: 2px solid var(--fg); outline-offset: 2px; }
.actions { flex: none; display: flex; gap: 2px; }
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; background: none;
  color: var(--fg); border-radius: 999px; cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--chip); }
.icon-btn svg, .scroller svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- reading content (the approved v1 look) ---------- */
main { padding-block: 8px 140px; }
#panels:focus { outline: none; }
.panel h2 { font-size: 1.35rem; font-weight: 600; margin: 24px 0 2px; }
.panel .sub { color: var(--muted); margin: 0 0 8px; font-size: calc(0.95rem * var(--en-scale)); }

ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
li.step { counter-increment: step; border-top: 1px solid var(--line); padding-block: 22px 18px; display: grid; gap: 14px; }
.step-head { display: flex; align-items: baseline; gap: 10px; }
.step-head::before {
  content: counter(step); font-variant-numeric: tabular-nums; font-size: 0.8rem; color: var(--muted);
  min-width: 1.6em; text-align: center; border-radius: 999px; transition: background-color 0.2s, color 0.2s;
}
.step-head h3 { margin: 0; font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
:root[data-highlight="on"] li.step.current .step-head::before { background: var(--fg); color: var(--bg); padding: 0 0.45em; min-width: 1.9em; }
:root[data-highlight="on"] li.step.current .step-head h3 { color: var(--fg); }

li.pause { border-top: 1px dashed var(--line); padding-block: 14px; color: var(--muted); font-style: italic; text-align: center; font-size: calc(0.95rem * var(--en-scale)); }

.line { display: grid; gap: 4px; }
.line + .line { margin-top: 10px; }
.cue { margin: 0; font-style: italic; color: var(--muted); font-size: calc(0.92rem * var(--en-scale)); }
.arrow { display: flex; align-items: flex-start; gap: 12px; direction: rtl; }
.ar {
  font-family: var(--ar-font); font-size: calc(var(--ar-size) * var(--ar-scale)); line-height: calc(2.05 * var(--lh-scale));
  margin: 0; direction: rtl; text-align: right; flex: 1; min-width: 0; overflow-wrap: break-word;
}
.en { margin: 0; font-size: calc(1rem * var(--en-scale)); line-height: calc(1.5 * var(--lh-scale)); overflow-wrap: break-word; }
.n {
  direction: ltr; flex: none; margin-top: 0.55em; font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums;
  border: 1px solid var(--fg); border-radius: 999px; padding: 1px 9px; white-space: nowrap; background: none; line-height: 1.5;
  font-family: var(--en-font);
}
.n.once { border-color: var(--line); color: var(--muted); font-weight: 400; }
.lead { padding-bottom: 8px; border-bottom: 1px dotted var(--line); margin-bottom: 4px; display: grid; gap: 4px; }

/* tap-to-count tally: the count badge becomes a button with a 44px hit area */
button.n.tally { position: relative; cursor: pointer; min-width: 3.4em; }
button.n.tally::after { content: ""; position: absolute; inset: -12px -10px; }
button.n.tally.counting { background: var(--chip); }
button.n.tally.done { background: var(--fg); color: var(--bg); }

.names { direction: rtl; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; }
.names .cell { display: grid; gap: 0; padding-block: 4px; border-bottom: 1px dotted var(--line); min-width: 0; }
.names .ar { font-size: calc(var(--ar-size) * var(--ar-scale) * 0.88); line-height: calc(1.9 * var(--lh-scale)); }
.names .en { font-size: calc(0.85rem * var(--en-scale)); color: var(--muted); text-align: right; }

.pairs { display: grid; gap: 12px; }
.pair { display: grid; gap: 0; padding-bottom: 10px; border-bottom: 1px dotted var(--line); }
.pair .ar { line-height: calc(1.9 * var(--lh-scale)); }
.pair .refrain { font-size: calc(var(--ar-size) * var(--ar-scale) * 0.78); color: var(--muted); }
.pair .en { font-size: calc(0.92rem * var(--en-scale)); }

.end-note { text-align: center; color: var(--muted); font-size: 0.9rem; padding-top: 28px; border-top: 1px solid var(--line); }

/* ---------- show / hide settings ---------- */
:root[data-show-en="off"] .en,
:root[data-show-en="off"] .lead .en { display: none; }
:root[data-show-cues="off"] .cue,
:root[data-show-cues="off"] li.pause { display: none; }
:root[data-show-counts="off"] .n { display: none; }
:root[data-show-titles="off"] .step-head { display: none; }
:root[data-show-titles="off"] li.step { padding-block: 16px 14px; }
:root[data-ar-align="center"] .ar { text-align: center; }
:root[data-ar-align="center"] .names .en { text-align: center; }
:root[data-ar-align="center"] .en,
:root[data-ar-align="center"] .cue { text-align: center; }

/* ---------- auto-scroll control ---------- */
.scroller {
  position: fixed; z-index: 8; right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 8px; font-family: var(--ui-font);
}
.scroller-toggle {
  width: 56px; height: 56px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); padding: 0;
}
.scroller-toggle svg { width: 24px; height: 24px; }
.scroller .i-pause { display: none; }
.scroller[data-running="true"] .i-play { display: none; }
.scroller[data-running="true"] .i-pause { display: block; }
.scroller[data-running="true"] .scroller-toggle { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.scroller-speed {
  display: none; align-items: center; height: 48px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 0 2px;
}
.scroller[data-running="true"] .scroller-speed { display: flex; }
.scroller-speed button { width: 44px; height: 44px; border: 0; background: none; border-radius: 999px; display: grid; place-items: center; cursor: pointer; padding: 0; }
.scroller-speed button:hover { background: var(--chip); }
.scroller-speed output { min-width: 3.6em; text-align: center; font-size: 0.85rem; line-height: 1.1; }
.scroller-speed output .lbl { display: block; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.scroller-speed output b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.scroller-note {
  font-size: 0.85rem; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.25s; pointer-events: none; white-space: nowrap;
}
.scroller-note.show { opacity: 1; }
:root[data-show-scroller="off"] .scroller { display: none; }

/* ---------- sheets (settings + downloads) ---------- */
dialog.sheet {
  padding: 0; border: 1px solid var(--line); background: var(--surface); opacity: 1; color: var(--fg);
  width: min(560px, calc(100vw - 32px)); max-height: min(86vh, 820px); border-radius: 16px; box-shadow: var(--shadow);
  font-family: var(--ui-font); font-size: 16px; overflow: hidden;
}
dialog.sheet::backdrop { background: var(--scrim); }
dialog.sheet[open] { display: flex; }
.sheet-inner { background: var(--surface); display: flex; flex-direction: column; width: 100%; max-height: inherit; min-height: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 20px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px calc(20px + env(safe-area-inset-bottom, 0px)); min-height: 0; }

@media (max-width: 640px) {
  dialog.sheet {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0;
    max-height: 78vh; max-height: 78dvh;
  }
  dialog.sheet[open] { animation: sheet-up 0.22s ease-out; }
}
@keyframes sheet-up { from { transform: translateY(40px); } to { transform: none; } }

.group { border: 0; margin: 0; padding: 14px 0 6px; border-bottom: 1px solid var(--line); min-width: 0; }
.group:last-of-type { border-bottom: 0; }
.group legend { padding: 0; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); float: left; width: 100%; margin-bottom: 8px; }
.group legend + * { clear: both; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 8px; line-height: 1.4; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 48px; cursor: pointer; }
.switch-row small { color: var(--muted); font-size: 0.8rem; }
input[type="checkbox"][role="switch"] {
  -webkit-appearance: none; appearance: none; flex: none; width: 46px; height: 28px; border-radius: 999px; margin: 0;
  background: var(--line); position: relative; cursor: pointer; transition: background-color 0.15s;
}
input[type="checkbox"][role="switch"]::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,0.3); transition: transform 0.15s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--fg); }
input[type="checkbox"][role="switch"]:checked::before { transform: translateX(18px); background: var(--bg); }

.range-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; padding-block: 8px; }
.range-row label { font-size: 1rem; }
.range-row output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; }
.range-row input { grid-column: 1 / -1; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: none; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: var(--fg); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--fg); margin-top: -11px; }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--fg); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--fg); }

.choices { display: grid; gap: 6px; margin: 4px 0 8px; }
.choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choices.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.choice { position: relative; min-width: 0; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice > span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  min-height: 48px; padding: 8px 6px; border: 1px solid var(--line); border-radius: 12px; font-size: 0.88rem; line-height: 1.2;
}
.choice input:checked + span { border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); font-weight: 600; }
.choice input:focus-visible + span { outline: 2px solid var(--fg); outline-offset: 2px; }
.choice .sample { font-weight: 400; font-size: 1.35rem; line-height: 1.6; }
.choice .sample.f-serif, .choice .sample.f-sans { font-size: 1.2rem; line-height: 1.2; }
.sw { display: block; width: 22px; height: 22px; border-radius: 50%; border: 1px solid #8884; }
.sw-system { background: linear-gradient(135deg, #fdfdfc 50%, #121212 50%); }
.sw-light { background: #fdfdfc; }
.sw-sepia { background: #f6f0e3; }
.sw-dark { background: #121212; }
.sw-black { background: #000; }

.sheet-foot { display: flex; justify-content: space-between; gap: 10px; padding-top: 16px; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line); background: none; cursor: pointer; font-size: 0.95rem; }
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* download list */
.files { list-style: none; margin: 10px 0 0; padding: 0; }
.files li + li { border-top: 1px solid var(--line); }
.files li.rec { border: 1px solid var(--fg); border-radius: 12px; margin-bottom: 8px; }
.files li.rec + li { border-top: 0; }
.files a { display: flex; align-items: center; gap: 12px; padding: 12px 10px; min-height: 56px; color: inherit; text-decoration: none; border-radius: 12px; }
.files a:hover { background: var(--chip); }
.files .txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.files .name { font-weight: 600; font-size: 1rem; }
.files .desc { color: var(--muted); font-size: 0.85rem; line-height: 1.35; }
.files .tag { display: inline-block; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; border: 1px solid currentColor; border-radius: 999px; padding: 0 7px; margin-left: 6px; vertical-align: 2px; color: var(--muted); }
.files li.rec .tag.rec-tag { color: var(--fg); }
.files .dl { flex: none; width: 40px; height: 40px; border-radius: 999px; display: grid; place-items: center; border: 1px solid var(--line); }
.files .dl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- small screens ---------- */
@media (max-width: 480px) {
  :root { --ar-size: 1.6rem; }
  header.top { padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
  header.top h1 { font-size: 1.6rem; }
  .names { grid-template-columns: minmax(0, 1fr); }
  .tab > span { padding-inline: 8px; }
  .choices.five { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .choices.five .choice > span { font-size: 0.78rem; padding-inline: 2px; }
  .choice .sample { font-size: 1.15rem; }
}

@media (max-width: 380px) { .tab { font-size: 0.9rem; } .tab > span { padding-inline: 7px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
