/* أحاديث إنعام — paper and ink.

   Warm paper, deep teal ink, a little gold. Every colour is a token on :root
   and redefined for dark, both when the phone asks for it and when the reader
   picks it with the moon button (data-theme on <html>). */

@font-face {
  font-family: "Amiri"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(/fonts/amiri-arabic-400-normal.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "Amiri"; font-weight: 700; font-style: normal; font-display: swap;
  src: url(/fonts/amiri-arabic-700-normal.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-400-arabic.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-400-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-500-arabic.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-500-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-700-arabic.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-700-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }

:root {
  --bg: #f7f1e6;
  --paper: #fffdf8;
  --paper-2: #f2eadb;
  --ink: #1d2b2c;
  --ink-soft: #5f6b68;
  --ink-faint: #8a928c;
  --teal: #1f5f5b;
  --teal-soft: #e3eeeb;
  --teal-ink: #ffffff;
  --gold: #a87a2e;
  --gold-soft: #f4e6c8;
  --line: #e2d8c5;
  --line-strong: #c8b994;
  --bad: #b3413a;
  --bad-bg: #f8e2dd;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 10px 28px rgba(60, 45, 20, .07);
  --r: 16px;
  --sans: "Plex Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --naskh: "Amiri", "Noto Naskh Arabic", "Traditional Arabic", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14191a;
    --paper: #1b2223;
    --paper-2: #222b2c;
    --ink: #ece4d4;
    --ink-soft: #b2ab9c;
    --ink-faint: #858073;
    --teal: #7fc4ba;
    --teal-soft: #213433;
    --teal-ink: #0e1a19;
    --gold: #e0b866;
    --gold-soft: #3a3020;
    --line: #2f3a3a;
    --line-strong: #4d5a57;
    --bad: #f08f86;
    --bad-bg: #432421;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 30px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #14191a;
  --paper: #1b2223;
  --paper-2: #222b2c;
  --ink: #ece4d4;
  --ink-soft: #b2ab9c;
  --ink-faint: #858073;
  --teal: #7fc4ba;
  --teal-soft: #213433;
  --teal-ink: #0e1a19;
  --gold: #e0b866;
  --gold-soft: #3a3020;
  --line: #2f3a3a;
  --line-strong: #4d5a57;
  --bad: #f08f86;
  --bad-bg: #432421;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
/* A class selector outranks the UA stylesheet's own `[hidden] { display: none }`,
   and several rules below set `display`. Without this, `el.hidden = true` on
   one of them hides nothing (in vault, the unlocked vault showed through the
   lock screen). Keep it; tests/ui.test.mjs probes it. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.75 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--teal); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; background: var(--paper); padding: 6px 10px; z-index: 10; }

.sandbox { background: var(--gold); color: var(--teal-ink); text-align: center; font-size: 13px; padding: 4px 12px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; }
.brand-mark path { fill: var(--teal); }
.brand-mark circle { fill: var(--gold-soft); }
.brand-name { font-family: var(--naskh); font-weight: 700; font-size: 22px; line-height: 1; }
.top-right { display: flex; align-items: center; gap: 8px; }
.owner-pill { font-size: 12px; background: var(--gold-soft); color: var(--gold); border-radius: 99px; padding: 3px 10px; font-weight: 500; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--line); background: var(--paper); border-radius: 50%; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-soft); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- layout ---- */
.layout { width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 16px 48px; flex: 1; outline: none; }
.loading { color: var(--ink-faint); text-align: center; padding: 60px 0; }

.footer { text-align: center; color: var(--ink-faint); font-size: 13px; padding: 24px 16px 40px; border-top: 1px solid var(--line); }
.footer p { margin: 4px 0; }
.footer a { color: var(--ink-faint); }

/* ---- home ---- */
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-family: var(--naskh); font-size: clamp(34px, 7vw, 48px); line-height: 1.3; margin: 0; font-weight: 700; }
.hero .welcome { color: var(--ink-soft); font-size: 17px; max-width: 34em; margin: 8px auto 0; white-space: pre-line; }
.ornament { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--gold); margin: 14px 0; }
.ornament::before, .ornament::after { content: ""; height: 1px; width: 60px; background: linear-gradient(to left, transparent, var(--line-strong)); }
.ornament::after { transform: scaleX(-1); }
.ornament svg { width: 14px; height: 14px; fill: currentColor; }

.today {
  display: block; text-decoration: none; color: inherit;
  background: var(--teal); color: var(--teal-ink);
  border-radius: calc(var(--r) + 4px); padding: 22px 22px 18px; margin: 18px 0 28px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.today::after {
  content: ""; position: absolute; inset-inline-end: -40px; top: -40px; width: 160px; height: 160px; opacity: .12;
  background: radial-gradient(circle, var(--gold-soft) 0 30%, transparent 31%) , conic-gradient(from 22.5deg, var(--gold-soft) 0 12.5%, transparent 0 25%, var(--gold-soft) 0 37.5%, transparent 0 50%, var(--gold-soft) 0 62.5%, transparent 0 75%, var(--gold-soft) 0 87.5%, transparent 0);
  border-radius: 50%;
}
.today .k { font-size: 13px; opacity: .85; letter-spacing: .02em; }
.today .t { font-family: var(--naskh); font-size: 24px; font-weight: 700; margin: 4px 0 6px; }
.today .q { font-family: var(--naskh); font-size: 20px; line-height: 1.9; margin: 0; opacity: .95; }
.today .more { display: inline-block; margin-top: 10px; font-size: 14px; border-bottom: 1px solid currentColor; }

.coll-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.coll-head h2 { font-family: var(--naskh); font-size: 28px; margin: 0; }
.coll-head .by { color: var(--ink-soft); font-size: 14px; }
.about { color: var(--ink-soft); margin: 6px 0 16px; }

.tools { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.search {
  width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 12px;
  padding: 10px 14px; font-size: 16px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--paper); color: var(--ink-soft);
  border-radius: 99px; padding: 5px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }

.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.card {
  display: flex; gap: 12px; align-items: flex-start; text-decoration: none; color: inherit;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px;
  transition: border-color .15s, transform .15s;
  height: 100%;
}
.card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.star { flex: none; position: relative; width: 40px; height: 40px; display: grid; place-items: center; }
.star svg { position: absolute; inset: 0; width: 100%; height: 100%; fill: var(--gold-soft); stroke: var(--gold); stroke-width: .8; }
.star b { position: relative; font-size: 14px; color: var(--gold); font-weight: 700; }
.card .t { font-family: var(--naskh); font-weight: 700; font-size: 19px; line-height: 1.5; }
.card .m { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.card .m .her { color: var(--gold); }
.card .m > span + span::before { content: ""; display: inline-block; width: 3px; height: 3px; border-radius: 50%; background: currentColor; margin-inline-end: 8px; vertical-align: middle; }
.empty { color: var(--ink-faint); text-align: center; padding: 24px 0; }

/* ---- hadith ---- */
.crumbs { display: flex; justify-content: space-between; align-items: center; font-size: 14px; margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.h-head { text-align: center; margin: 6px 0 18px; }
.h-head .star { margin: 0 auto 6px; width: 54px; height: 54px; }
.h-head .star b { font-size: 18px; }
.h-head h1 { font-family: var(--naskh); font-size: clamp(28px, 6vw, 38px); line-height: 1.4; margin: 0; }
.h-head .theme { display: inline-block; margin-top: 8px; font-size: 13px; color: var(--teal); background: var(--teal-soft); border-radius: 99px; padding: 2px 12px; text-decoration: none; }

.text-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: calc(var(--r) + 4px);
  padding: 22px clamp(18px, 4vw, 34px); box-shadow: var(--shadow); position: relative;
}
.text-card::before {
  content: ""; position: absolute; inset: 6px; border: 1px solid var(--gold-soft); border-radius: var(--r); pointer-events: none;
}
.intro { color: var(--ink-soft); font-family: var(--naskh); font-size: 18px; line-height: 2; margin: 0 0 6px; }
.matn { font-family: var(--naskh); font-size: clamp(23px, 4.4vw, 28px); line-height: 2.2; margin: 0; color: var(--ink); }
.variant { font-family: var(--naskh); font-size: clamp(20px, 3.8vw, 23px); line-height: 2.1; color: var(--ink-soft); margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.takhrij { margin: 14px 0 0; font-size: 14px; color: var(--gold); display: flex; align-items: center; gap: 6px; }
.takhrij::before { content: ""; width: 18px; height: 1px; background: var(--gold); }
.text-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 99px;
  padding: 7px 16px; font-size: 14px; font-weight: 500;
}
.btn:hover { border-color: var(--line-strong); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-soft); padding-inline: 8px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.en { direction: ltr; text-align: left; font-family: Georgia, "Times New Roman", serif; color: var(--ink-soft); font-size: 16px; line-height: 1.7; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }

.section { margin-top: 30px; }
.section > h2 { display: flex; align-items: center; gap: 10px; font-size: 18px; margin: 0 0 12px; color: var(--teal); font-weight: 700; }
.section > h2 svg { width: 20px; height: 20px; fill: none; stroke: var(--gold); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.section p.body { margin: 0; font-size: 17px; line-height: 1.95; }

.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin: 0; }
.words div { background: var(--paper-2); border-radius: 12px; padding: 10px 12px; }
.words dt { font-family: var(--naskh); font-weight: 700; font-size: 19px; color: var(--ink); }
.words dd { margin: 0; color: var(--ink-soft); font-size: 14.5px; line-height: 1.7; }

.comm { display: grid; gap: 10px; }
.comm article { background: var(--paper); border: 1px solid var(--line); border-inline-start: 3px solid var(--gold); border-radius: 12px; padding: 12px 14px; }
.comm .who { font-weight: 700; font-size: 14px; color: var(--ink); }
.comm .book { font-weight: 400; color: var(--ink-faint); font-size: 13px; }
.comm p { margin: 4px 0 0; font-size: 16px; line-height: 1.9; }

.daily { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.daily li { display: flex; gap: 12px; align-items: flex-start; background: var(--teal-soft); border-radius: 12px; padding: 12px 14px; font-size: 16px; line-height: 1.85; }
.daily .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--teal); color: var(--teal-ink); display: grid; place-items: center; font-size: 13px; font-weight: 700; margin-top: 2px; }

.ask { text-align: center; background: var(--gold-soft); border-radius: calc(var(--r) + 4px); padding: 22px 20px; margin-top: 30px; }
.ask .k { font-size: 13px; color: var(--gold); font-weight: 700; }
.ask p { font-family: var(--naskh); font-size: 22px; line-height: 1.8; margin: 6px 0 0; }

.her-note { margin-top: 30px; background: var(--paper); border: 1px solid var(--gold); border-radius: calc(var(--r) + 4px); padding: 18px 20px; position: relative; }
.her-note .k { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--gold); font-size: 14px; }
.her-note .k svg { width: 18px; height: 18px; fill: var(--gold); }
.her-note p { margin: 8px 0 0; font-family: var(--naskh); font-size: 20px; line-height: 1.95; white-space: pre-line; }
.her-note .when { color: var(--ink-faint); font-size: 12.5px; margin-top: 6px; }

.editor { display: grid; gap: 8px; margin-top: 10px; }
textarea, .input {
  width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 12px;
  padding: 10px 12px; font-size: 16px; line-height: 1.8; resize: vertical;
}
textarea:focus, .input:focus, .search:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; }
.hint { color: var(--ink-faint); font-size: 13px; }
.err { color: var(--bad); font-size: 14px; }

/* ---- reflections ---- */
.reflect-form { background: var(--paper); border: 1px solid var(--line); border-radius: calc(var(--r) + 4px); padding: 16px; display: grid; gap: 10px; }
.reflect-form label { font-size: 14px; color: var(--ink-soft); display: grid; gap: 4px; }
.hp { position: absolute; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
.refl { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.refl > li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.refl > li.pinned { border-color: var(--gold); }
.refl > li.is-hidden { opacity: .6; border-style: dashed; }
.refl .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.refl .name { font-weight: 700; unicode-bidi: isolate; }
.refl .when { color: var(--ink-faint); font-size: 12.5px; }
.refl .tag { font-size: 12px; color: var(--gold); margin-inline-start: 6px; font-weight: 500; }
.refl .words-of { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.9; }
.refl .reply { margin-top: 10px; background: var(--gold-soft); border-radius: 12px; padding: 8px 12px; }
.refl .reply .k { font-size: 12.5px; color: var(--gold); font-weight: 700; }
.refl .reply p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.refl .acts { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 8px; margin-inline-start: -8px; }
.like[aria-pressed="true"] { color: var(--bad); }
.like[aria-pressed="true"] svg { fill: currentColor; }
.count { font-variant-numeric: tabular-nums; }
.count-of { font-weight: 400; color: var(--ink-faint); font-size: 14px; margin-inline-start: 4px; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 36px; }
.pager a { flex: 1; text-decoration: none; color: inherit; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.pager a:last-child { text-align: left; }
.pager .k { font-size: 12.5px; color: var(--ink-faint); display: block; }
.pager .t { font-family: var(--naskh); font-weight: 700; font-size: 17px; }

/* ---- sign in ---- */
.signin { max-width: 420px; margin: 30px auto; background: var(--paper); border: 1px solid var(--line); border-radius: calc(var(--r) + 4px); padding: 24px; box-shadow: var(--shadow); }
.signin h1 { font-family: var(--naskh); margin: 0 0 6px; font-size: 28px; }
.signin form { display: grid; gap: 10px; margin-top: 14px; }

.toast {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px; z-index: 20;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

@media (max-width: 520px) {
  .layout { padding-top: 12px; }
  .grid { grid-template-columns: 1fr; }
  .today { padding: 18px 16px 16px; }
  .today .q { font-size: 18px; }
  .pager { flex-direction: column; }
  .pager a:last-child { text-align: right; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
