:root {
  --bg: #f4efe6; --surface: #fffdf8; --ink: #2a2722; --muted: #857c6e;
  --accent: #0e7490; --accent-ink: #0b5c73; --warn: #b45309; --bad: #b91c1c;
  --ok: #15803d; --line: #e6ddcc; --soft: #efe9db;
  --shadow: 0 1px 3px rgba(90,75,45,.10), 0 8px 24px rgba(90,75,45,.06);
  --serif: "Iowan Old Style", "Palatino Nova", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fa: "Geeza Pro", "Noto Naskh Arabic", "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191713; --surface: #211f1a; --ink: #e8e2d5; --muted: #968d7d;
    --accent: #4fb3cd; --accent-ink: #7accdf; --warn: #d97706; --bad: #ef4444;
    --ok: #4ade80; --line: #35322a; --soft: #26231e;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
       font-family: var(--serif); font-size: 16px; line-height: 1.6; }
a { color: var(--accent); }
button, .btn {
  font-family: var(--sans); font-size: .84rem; cursor: pointer;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 7px 14px; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-ink); }
button.ghost, .btn.ghost { background: var(--surface); color: var(--muted);
  border: 1px solid var(--line); }
button.ghost:hover { color: var(--ink); }
button.danger { background: var(--bad); }
input, select, textarea {
  font: inherit; font-size: .9rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; outline: none; max-width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center;
  gap: 18px; padding: 10px clamp(12px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); font-family: var(--sans);
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.1rem;
  color: var(--ink); text-decoration: none; }
.brand em { color: var(--accent-ink); font-style: normal; font-weight: 400; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted); text-decoration: none; font-size: .85rem;
  padding: 5px 11px; border-radius: 8px;
}
.topbar nav a:hover { background: var(--soft); color: var(--ink); }
.topbar nav a.cur { background: var(--accent); color: #fff; }
.spacer { flex: 1; }
.whoami { display: flex; align-items: center; gap: 8px; font-size: .82rem;
  color: var(--muted); }
.whoami img { width: 26px; height: 26px; border-radius: 50%; }
.role { font-size: .68rem; padding: 2px 8px; border-radius: 999px;
  background: var(--soft); border: 1px solid var(--line); }
.role-admin { background: var(--accent); color: #fff; border: none; }
.role-author { background: var(--ok); color: #fff; border: none; }
.role-editor { background: var(--warn); color: #fff; border: none; }
.logout { font-size: .8rem; color: var(--muted); }
main { max-width: 1150px; margin: 0 auto; padding: 26px clamp(12px,3vw,32px) 80px; }
main.wide { max-width: 1400px; }
h1 { font-weight: 600; }
.muted { color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 20px 24px;
}
/* home volume grid */
.vol-grid { display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.vol-card { position: relative; overflow: hidden; display: block;
  text-decoration: none; color: var(--ink); transition: transform .15s; }
.vol-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.vol-card .roman { position: absolute; right: 4px; top: -22px;
  font-size: 5.6rem; font-weight: 700; color: var(--accent); opacity: .08; }
/* reader */
.verse-card { position: relative; margin-bottom: 16px; }
.verse-card .vnum { position: absolute; top: 12px; left: 16px;
  font-family: var(--sans); font-size: .78rem; font-weight: 600;
  color: var(--muted); }
.divider { margin: 40px 0 22px; text-align: center; }
.divider .orn { color: var(--accent); letter-spacing: .5em; padding-left: .5em; }
.divider h3 { margin: 8px auto 0; max-width: 720px; font-size: 1.04rem; }
.seg-grid { display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.fa-line { font-family: var(--fa); direction: rtl; text-align: center;
  font-size: 1.45rem; line-height: 2.1; margin: 4px auto 12px; }
.fa-line .sep { color: var(--accent); font-size: .8em; margin: 0 .7em; }
.seg h4 { margin: 0 0 4px; font-family: var(--sans); font-weight: 600;
  font-size: .64rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent-ink); display: flex; gap: 8px; align-items: center; }
.seg p, .seg .st { margin: 0; font-size: .93rem; }
.seg .none { color: var(--muted); opacity: .6; font-style: italic;
  font-size: .84rem; }
.seg [contenteditable]:focus { background: #eaf3f6; border-radius: 6px;
  box-shadow: 0 0 0 2px #0e749055; outline: none; }
details.serh { margin-top: 6px; }
details.serh summary { cursor: pointer; list-style: none; user-select: none;
  font-family: var(--sans); font-size: .7rem; letter-spacing: .06em;
  color: var(--accent); text-transform: uppercase; }
details.serh summary::before { content: "❧ "; }
details.serh .st { margin-top: 6px; padding: 8px 12px;
  border-left: 2px solid var(--accent); border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  font-size: .87rem; line-height: 1.65; white-space: pre-line;
  max-height: 380px; overflow-y: auto; }
.seg-tools { visibility: hidden; display: inline-flex; gap: 4px; }
.seg:hover .seg-tools { visibility: visible; }
.seg-tools button { padding: 1px 7px; font-size: .72rem; border-radius: 5px;
  background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.seg-tools button:hover { background: var(--accent); color: #fff; }
/* annotations */
.annots { margin-top: 12px; border-top: 1px dashed var(--line);
  padding-top: 10px; display: grid; gap: 8px; }
.annot { font-size: .87rem; padding: 9px 13px; border-radius: 10px;
  background: var(--soft); }
.annot .who { font-family: var(--sans); font-size: .7rem; color: var(--muted); }
.annot.note { border-left: 3px solid var(--ok); }
.annot.quran { border-left: 3px solid var(--accent); }
.annot.hadith { border-left: 3px solid var(--warn); }
.annot.assoc { border-left: 3px solid #8b5cf6; }
.badge { font-family: var(--sans); font-size: .66rem; letter-spacing: .06em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); }
/* pager & toolbar */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px; font-family: var(--sans); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center;
  margin: 26px 0; font-family: var(--sans); font-size: .85rem; }
/* author panel */
.author-tools { margin: 6px 0 0; }
.author-tools summary { cursor: pointer; font-family: var(--sans);
  font-size: .72rem; color: var(--muted); user-select: none; }
.author-form { display: grid; gap: 8px; padding: 12px; margin-top: 8px;
  background: var(--soft); border-radius: 10px; font-family: var(--sans);
  font-size: .84rem; }
.author-form .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.author-form input[type=number] { width: 90px; }
/* tables */
table.list { width: 100%; border-collapse: collapse; background: var(--surface);
  font-size: .88rem; font-family: var(--sans); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow); }
table.list th { background: var(--soft); color: var(--muted); text-align: left;
  font-size: .7rem; letter-spacing: .08em; text-transform: uppercase;
  padding: 9px 12px; }
table.list td { border-top: 1px solid var(--line); padding: 8px 12px;
  vertical-align: top; }
/* chat */
.chat-wrap { max-width: 820px; margin: 0 auto; }
.chat-msgs { display: grid; gap: 12px; margin-bottom: 18px; }
.msg { padding: 12px 16px; border-radius: 14px; max-width: 92%; }
.msg.user { background: var(--accent); color: #fff; justify-self: end; }
.msg.assistant { background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); white-space: pre-line; }
.msg .cites { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg .cites a { font-family: var(--sans); font-size: .72rem;
  text-decoration: none; padding: 2px 9px; border-radius: 999px;
  background: var(--soft); border: 1px solid var(--line); color: var(--accent-ink); }
.chat-input { display: flex; gap: 8px; position: sticky; bottom: 14px; }
.chat-input textarea { flex: 1; resize: none; min-height: 52px; }
.thinking { color: var(--muted); font-style: italic; }
/* login */
.login-hero { min-height: 80vh; display: grid; place-items: center; }
.login-box { text-align: center; max-width: 430px; }
.login-box .fa-line { font-size: 1.4rem; }
.vref { font-family: var(--sans); font-size: .85em; text-decoration: none;
  padding: 1px 7px; border-radius: 6px; background: var(--soft);
  border: 1px solid var(--line); }
article.prose { max-width: 760px; margin: 0 auto; }
article.prose h1 { font-size: 1.9rem; }
article.prose p { line-height: 1.75; }
.flash { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-family: var(--sans);
  font-size: .85rem; padding: 9px 18px; border-radius: 10px; z-index: 99;
  opacity: 0; transition: opacity .2s; pointer-events: none; }
.flash.show { opacity: 1; }
