@font-face { font-family: "Plex Arabic"; src: url(../fonts/plex-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url(../fonts/plex-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Latin"; src: url(../fonts/plex-latin-400.woff2) format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Amiri"; src: url(../fonts/amiri-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Amiri"; src: url(../fonts/amiri-700.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --bg: #f5f0e6;
  --surface: #fffcf5;
  --surface-2: #efe8da;
  --ink: #1d2621;
  --ink-2: #4c554f;
  --muted: #7a7f77;
  --line: #e1d8c6;
  --accent: #2e6a4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2eee6;
  --gold: #a5822f;
  --caution: #a45a1c;
  --caution-soft: #f7e9d9;
  --done: #8aa596;
  --shadow: 0 1px 2px rgb(40 30 10 / 6%), 0 4px 16px rgb(40 30 10 / 6%);
  --radius: 14px;
  --sky-a: #e9e2d2;
  --sky-b: #f5f0e6;
  --font-ui: "Plex Latin", "Plex Arabic", "Segoe UI", Tahoma, "Amiri", sans-serif;
  --font-text: "Amiri", "Traditional Arabic", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614; --surface: #17201c; --surface-2: #1e2924; --ink: #ebe6da; --ink-2: #c3c3b6; --muted: #8d948c;
    --line: #2a3631; --accent: #7fbf9c; --accent-ink: #0d1411; --accent-soft: #1f3329; --gold: #d4b46a;
    --caution: #e0a26a; --caution-soft: #33261a; --done: #4f6b5c; --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    --sky-a: #1a2420; --sky-b: #101614; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101614; --surface: #17201c; --surface-2: #1e2924; --ink: #ebe6da; --ink-2: #c3c3b6; --muted: #8d948c;
  --line: #2a3631; --accent: #7fbf9c; --accent-ink: #0d1411; --accent-soft: #1f3329; --gold: #d4b46a;
  --caution: #e0a26a; --caution-soft: #33261a; --done: #4f6b5c; --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  --sky-a: #1a2420; --sky-b: #101614; color-scheme: dark;
}

/* The hero takes the colour of the sky at this hour. */
body[data-sky="dawn"]  { --sky-a: #e5dbe6; --sky-b: #f3e6da; }
body[data-sky="day"]   { --sky-a: #dde9ee; --sky-b: #f3efe4; }
body[data-sky="asr"]   { --sky-a: #f1e1bf; --sky-b: #f5eddc; }
body[data-sky="dusk"]  { --sky-a: #efcfb8; --sky-b: #e4d6e3; }
body[data-sky="night"] { --sky-a: #d9dbe6; --sky-b: #ebe8e6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body[data-sky="dawn"]  { --sky-a: #2a2433; --sky-b: #1b1d22; }
  :root:not([data-theme="light"]) body[data-sky="day"]   { --sky-a: #1b2a30; --sky-b: #151d1b; }
  :root:not([data-theme="light"]) body[data-sky="asr"]   { --sky-a: #2f2716; --sky-b: #19201b; }
  :root:not([data-theme="light"]) body[data-sky="dusk"]  { --sky-a: #33221c; --sky-b: #211b26; }
  :root:not([data-theme="light"]) body[data-sky="night"] { --sky-a: #161b2c; --sky-b: #101614; }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 16px; line-height: 1.7;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
svg { width: 1.2em; height: 1.2em; fill: currentColor; flex: none; }
svg.stroke { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 1.25rem; margin-inline-end: auto; }
.brand .mark { width: 26px; height: 26px; color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 46vw; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .9rem; white-space: nowrap;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip svg { color: var(--accent); width: 1em; height: 1em; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
}

main { max-width: 760px; margin: 0 auto; padding: 0 16px 24px; }
main:focus { outline: none; }
.loading, .noscript { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Bottom tabs */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 200px; text-align: center; padding: 8px 4px; border-radius: 10px; text-decoration: none;
  color: var(--ink-2); font-size: .95rem;
}
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Hero */
.hero {
  margin: 16px -16px 0; padding: 24px 16px 18px;
  background: linear-gradient(180deg, var(--sky-a), var(--sky-b));
  border-bottom: 1px solid var(--line);
}
@media (min-width: 792px) { .hero { margin-inline: 0; border-radius: var(--radius); border: 1px solid var(--line); } }
.kicker { margin: 0; color: var(--ink-2); font-size: .95rem; }
.hero h1 { margin: 2px 0 0; font-size: clamp(1.9rem, 7vw, 2.6rem); line-height: 1.3; font-weight: 600; }
.until { margin: 2px 0 14px; color: var(--ink-2); }
.until b { color: var(--ink); font-weight: 600; }
.banner {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--gold);
  font-size: .92rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.banner button { margin-inline-start: auto; }

/* Day timeline: right (fajr) to left (next fajr) in RTL */
.track { position: relative; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); margin: 6px 0 4px; }
.seg { position: absolute; top: 0; bottom: 0; }
.seg.fajr, .seg.lastThird { background: #b7a9c9; }
.seg.sunrise, .seg.zawal { background: #d9b26a; }
.seg.duha, .seg.dhuhr { background: #a9cbd6; }
.seg.asr { background: #e2c27d; }
.seg.maghrib { background: #d99a7a; }
.seg.isha, .seg.bed, .seg.night { background: #6f7aa3; }
.seg.lastThird { background: #8c7fb8; }
.now-mark { position: absolute; top: -3px; bottom: -3px; width: 3px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); }
.track-legend { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }

.prayers { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.prayers li {
  text-align: center; padding: 6px 2px; border-radius: 10px; font-size: .8rem; color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.prayers li b { display: block; font-size: 1rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.prayers li.current { background: var(--accent); color: var(--accent-ink); }
.prayers li.current b { color: var(--accent-ink); }
.prayers li.next { outline: 1.5px solid var(--accent); }
@media (max-width: 380px) { .prayers { grid-template-columns: repeat(3, 1fr); } }

/* Sections and cards */
.sec { margin-top: 28px; }
.sec > h2 { font-size: 1.15rem; margin: 0 0 10px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
.sec > h2 small { font-weight: 400; color: var(--muted); font-size: .85rem; }
.cards { display: grid; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card h3 { margin: 0; font-size: 1.05rem; font-weight: 600; line-height: 1.5; }
.card p { margin: 4px 0 0; color: var(--ink-2); }
.card.caution { background: var(--caution-soft); border-color: color-mix(in srgb, var(--caution) 35%, transparent); box-shadow: none; }
.card.caution h3 { color: var(--caution); }
.card.adhkar { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; border-inline-start: 4px solid var(--accent); }
.card.adhkar .go { grid-row: span 2; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-inline-start: 6px; vertical-align: middle; font-weight: 400; }
.tag.review { background: var(--caution-soft); color: var(--caution); }
.progress { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; grid-column: 1 / -1; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; }

details.ev { margin-top: 8px; }
details.ev summary { cursor: pointer; color: var(--accent); font-size: .9rem; list-style: none; }
details.ev summary::-webkit-details-marker { display: none; }
details.ev summary::before { content: "◂ "; }
details.ev[open] summary::before { content: "▾ "; }
.ev blockquote { margin: 10px 0 0; padding: 0 12px 0 0; border-inline-start: 3px solid var(--line); font-family: var(--font-text); font-size: 1.2rem; line-height: 2; color: var(--ink); }
.ev cite { display: block; font-style: normal; font-family: var(--font-ui); font-size: .82rem; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); font-size: .95rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 32px; padding: 2px 12px; font-size: .88rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
.actions .btn { min-height: 52px; font-size: 1rem; }
.next-list { margin: 0; padding: 0 18px 0 0; color: var(--ink-2); }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 8px 0; }

/* Reader */
.reader-head { position: sticky; top: 61px; z-index: 4; background: var(--bg); padding: 12px 0 8px; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.reader-head h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.reader-head .progress { margin: 0; }
.dhikr {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 12px;
  box-shadow: var(--shadow); cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; transition: opacity .2s;
}
.dhikr .text { font-family: var(--font-text); font-size: clamp(1.3rem, 4.8vw, 1.55rem); line-height: 2.15; margin: 0; white-space: pre-line; }
.dhikr .meta { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.count {
  min-width: 52px; height: 52px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 600; font-size: 1.15rem;
  border: 2px solid var(--accent); color: var(--accent); background: var(--surface); font-variant-numeric: tabular-nums; cursor: pointer;
}
.dhikr .num { color: var(--muted); font-size: .8rem; }
.dhikr .rd { color: var(--ink-2); font-size: .9rem; }
.dhikr.done { opacity: .55; }
.dhikr.done .count { background: var(--done); border-color: var(--done); color: #fff; }
.dhikr.tick { animation: tick .18s ease-out; }
@keyframes tick { 50% { transform: scale(.985); } }
@media (prefers-reduced-motion: reduce) { .dhikr.tick { animation: none; } }
.dhikr details { margin-top: 10px; cursor: auto; }
.dhikr details summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.dhikr details p { margin: 6px 0 0; color: var(--ink-2); font-size: .95rem; }
.dhikr details .fadl { font-family: var(--font-text); font-size: 1.15rem; line-height: 1.9; color: var(--ink); }
.reader-foot { display: flex; gap: 10px; justify-content: center; margin: 20px 0; flex-wrap: wrap; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: .92rem; margin-top: 12px; }

/* Library */
.search { width: 100%; margin-top: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.group h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 22px 0 6px; }
.chapters { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chapters li + li { border-top: 1px solid var(--line); }
.chapters a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.chapters a:hover { background: var(--surface-2); }
.chapters small { color: var(--muted); white-space: nowrap; }

/* About */
.prose { max-width: 66ch; }
.prose h1 { font-size: 1.6rem; margin: 20px 0 4px; font-weight: 600; }
.prose h2 { font-size: 1.15rem; margin: 26px 0 6px; font-weight: 600; }
.prose li { margin: 4px 0; }

/* Settings dialog */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(10 15 12 / 45%); }
dialog form { padding: 0 18px 18px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 14px 0 6px; z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 1.2rem; }
fieldset { border: 0; border-top: 1px solid var(--line); padding: 14px 0 4px; margin: 6px 0 0; display: grid; gap: 10px; }
legend { font-weight: 600; padding: 0 0 4px; }
label { display: grid; gap: 4px; font-size: .92rem; color: var(--ink-2); }
input, select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); width: 100%; min-height: 44px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.hint { margin: 0; font-size: .84rem; color: var(--muted); }
.dlg-foot { display: flex; gap: 10px; padding-top: 16px; position: sticky; bottom: 0; background: var(--surface); padding-bottom: 4px; }
.dlg-foot .btn { flex: 1; }
details summary { cursor: pointer; }

/* Sky scene: the coastal ribāṭ under the real sky (js/coast.js draws it, js/sky.js sets the variables). */
.scene { position: relative; width: calc(100% + 32px); margin: -24px -16px 14px; overflow: hidden; background: #3f6f8f; }
@media (min-width: 560px) { .scene { width: 520px; max-width: 100%; margin: -8px auto 14px; border-radius: var(--radius); } }
.scene svg.coast { display: block; width: 100%; height: auto; aspect-ratio: 400 / 260; }
.m-stone { fill: var(--stone); }
.m-stone2 { fill: var(--stone2); }
.m-stone3 { fill: var(--stone3); }
.m-core { fill: var(--core); }
.m-rock { fill: var(--rock); }
.m-rock2 { fill: var(--rock2); }
.m-rock3 { fill: var(--rock3); }
.m-grass { fill: var(--grass); }
.m-tree { fill: var(--tree); }
.m-tree2 { fill: var(--tree2); }
.m-tree3 { fill: var(--tree3); }
.m-dome { fill: var(--dome); }
.m-white { fill: var(--white); }
.m-white2 { fill: var(--white2); }
.m-win { fill: var(--win); }
.m-door { fill: var(--door); }
.m-awn-r { fill: var(--awn-r); }
.m-awn-t { fill: var(--awn-t); }
.m-wood { fill: var(--wood); }
.m-sail { fill: var(--sail); }
.m-flag { fill: var(--flag); }
.m-cloud { fill: var(--cloud); }
.m-scloud { fill: var(--scloud); }
.m-scloud2 { fill: var(--scloud2); }
.s-top { stop-color: var(--sky-top); } .s-mid { stop-color: var(--sky-mid); } .s-hor { stop-color: var(--sky-hor); }
.s-sea0 { stop-color: var(--sea0); } .s-sea1 { stop-color: var(--sea1); } .s-sea2 { stop-color: var(--sea2); }
.s-sun { stop-color: var(--sun); }
.coast .sun-core { fill: var(--sun); }
.coast #moon { opacity: var(--moon-op); }
.coast .moon-dark { fill: rgb(40 50 86 / 55%); } .coast .moon-lit { fill: #f6f0d6; }
.coast .stars { fill: #fff; opacity: var(--stars); }
.coast .glint { fill: var(--glint); opacity: var(--glint-op); }
.coast .wave { fill: none; stroke: #fff; stroke-linecap: round; opacity: calc(.25 + .3 * var(--day)); }
.coast .crest, .coast .foam { fill: #f4f7f6; } .coast .foam-line { fill: none; stroke: #f4f7f6; stroke-width: 1.4; stroke-linecap: round; }
.coast .ink { stroke: var(--ink); stroke-width: .8; stroke-linejoin: round; }
.coast .ink-soft { stroke: var(--ink); stroke-width: .5; stroke-opacity: .6; stroke-linejoin: round; }
.coast .brick { stroke: var(--ink); stroke-width: .3; stroke-opacity: .4; opacity: .7; }
.coast .brick-line, .coast .band, .coast .ribs { fill: none; stroke: var(--ink); stroke-width: .5; stroke-opacity: .5; }
.coast .trunk { fill: none; stroke: var(--wood); stroke-width: 1.6; stroke-linecap: round; }
.coast .pole, .coast .scaffold, .coast .rope { fill: none; stroke: var(--ink); stroke-width: .8; stroke-linecap: round; }
.coast .scaffold { stroke: var(--wood); stroke-width: 1.1; }
.coast .rope { stroke-width: .4; }
.coast .bird { fill: none; stroke: #2c3036; stroke-width: .7; stroke-linecap: round; }
.coast .birds { opacity: var(--day); }
.coast .lit { fill: #ffd56e; opacity: var(--lit); }
.coast .glow { opacity: var(--lit); }
.coast .beam { opacity: calc(var(--lit) * var(--lit)); }
.coast .rays { mix-blend-mode: screen; opacity: var(--rays); }
.coast .flash { fill: #eef3ff; opacity: 0; }
.coast[data-weather="clear"] .storm-only, .coast[data-weather="storm"] .calm-only { display: none; }
.coast .works { display: none; } .coast.repairing .works { display: inline; }
/* Falling and rebuilding. */
.coast .part { transform-box: fill-box; transform-origin: 50% 100%; transition: transform 1.1s cubic-bezier(.55, 0, .9, .45), opacity 1.1s ease-in; }
.coast .part.gone { transform: translate(6px, 46px) rotate(18deg); opacity: 0; }
.coast .part.above { transform: translateY(-34px); opacity: 0; }
.coast .part.instant { transition: none; }
.coast .part:not(.gone):not(.above) { transition-timing-function: cubic-bezier(.2, .7, .3, 1.15), ease-out; }
.coast .ruin { opacity: 0; transition: opacity 1s .5s; } .coast .ruin.shown { opacity: 1; }
.scene-cap {
  position: absolute; margin: 0; inset-inline-start: 10px; bottom: 6px; font-size: .75rem; line-height: 1.4; color: #fff;
  text-shadow: 0 1px 3px rgb(0 0 0 / 70%);
}
.scene-demo { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -6px 0 12px; font-size: .8rem; }
.scene-demo input { flex: 1 1 140px; }
.scene-demo select, .scene-demo button { width: auto; flex: 0 0 auto; padding: 4px 8px; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { .coast .part, .coast .ruin { transition: none; } }
