: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;
}
/* Dark palette: applied when the system asks for it (unless the reader
   forced light), or when the reader explicitly picked dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --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);
  }
}
:root[data-theme="dark"] {
  --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);
}
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { 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: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-radius: 6px; box-shadow: 0 0 0 2px var(--accent); 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; }

/* source visibility chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; font-family: var(--sans); }
.chip { font-size: .72rem; letter-spacing: .04em; padding: 4px 11px;
  border-radius: 999px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  transition: all .15s; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
[hidden] { display: none !important; }

/* tema degistirme dugmesi */
.theme-btn {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; width: 32px; height: 32px; padding: 0;
  font-size: .95rem; line-height: 1; display: inline-flex;
  align-items: center; justify-content: center;
}
.theme-btn:hover { background: var(--soft); color: var(--ink); border-color: var(--accent); }

/* linked-section preview dialog */
.modal { position: fixed; inset: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(20, 16, 10, .55); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-box { background: var(--bg); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  width: min(760px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; font-family: var(--sans); font-size: .9rem; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); font-size: .8rem; }
.modal-body { overflow-y: auto; padding: 6px 18px 12px; }
.pv-verse { position: relative; padding: 14px 0 12px 34px;
  border-bottom: 1px solid var(--line); }
.pv-verse:last-child { border-bottom: none; }
.pv-num { position: absolute; left: 0; top: 16px; font-family: var(--sans);
  font-size: .74rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.pv-num:hover { color: var(--accent); }
.pv-heading { font-size: .82rem; font-style: italic; color: var(--muted);
  margin-bottom: 8px; }
.pv-fa { font-family: var(--fa); direction: rtl; text-align: center;
  font-size: 1.25rem; line-height: 2; margin: 2px 0 10px; }
.pv-seg { margin-bottom: 9px; }
.pv-seg h5 { margin: 0 0 2px; font-family: var(--sans); font-weight: 600;
  font-size: .6rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent-ink); }
.pv-seg p { margin: 0; font-size: .9rem; line-height: 1.55; }
.assoc-link { text-decoration: none; }
.assoc-link:hover { text-decoration: underline; }

/* ---------------- books ---------------- */
.bk-group { margin-bottom: 22px; }
.bk-group-title { font-family: var(--sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  border-left: 3px solid var(--accent); padding-left: 10px; margin: 22px 0 8px; }
.bk-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  margin-bottom: 7px; text-decoration: none; color: inherit; transition: border-color .15s; }
.bk-row:hover { border-color: var(--accent); }
.bk-no { font-family: var(--sans); font-size: .78rem; font-weight: 600;
  color: var(--muted); min-width: 22px; }
.bk-title { font-weight: 600; }
.bk-sum { display: block; font-weight: 400; font-size: .84rem; margin-top: 2px; }
.bk-done { background: var(--ok) !important; color: #fff !important; border: none !important; }
/* editor */
.bk-editor { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .bk-editor { grid-template-columns: 1fr; } }
.bk-side { position: sticky; top: 68px; max-height: calc(100vh - 90px);
  overflow-y: auto; font-size: .88rem; }
.bk-sema { font-family: var(--sans); font-size: .68rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); border-left: 3px solid var(--accent);
  padding-left: 9px; margin-bottom: 12px; }
.bk-beyit { background: var(--soft); border-radius: 10px; padding: 11px 13px; margin-bottom: 12px; }
.bk-fa { font-family: var(--fa); direction: rtl; font-size: 1.15rem; line-height: 1.9;
  margin: 6px 0 4px; }
.bk-beyit-tr { font-size: .9rem; }
.bk-meta { font-family: var(--sans); font-size: .8rem; margin-bottom: 6px; }
.bk-meta span { color: var(--muted); font-size: .68rem; letter-spacing: .08em;
  text-transform: uppercase; display: block; }
.bk-block { margin-top: 14px; }
.bk-block h5 { margin: 0 0 4px; font-family: var(--sans); font-size: .64rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); }
.bk-block div { line-height: 1.55; outline: none; border-radius: 6px; padding: 3px 5px; }
.bk-block div:focus { background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: 0 0 0 2px var(--accent); }
.bk-note div { background: color-mix(in srgb, var(--warn) 10%, transparent);
  border-left: 2px solid var(--warn); padding: 7px 10px; font-size: .86rem; }
.bk-empty:empty::before { content: "—"; color: var(--muted); }
.bk-nav { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px;
  display: grid; gap: 2px; font-family: var(--sans); font-size: .78rem; }
.bk-nav a { color: var(--muted); text-decoration: none; padding: 3px 7px; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-nav a:hover { background: var(--soft); color: var(--ink); }
.bk-nav a.cur { background: var(--accent); color: #fff; }
.bk-main { padding: 28px 34px 60px; }
.bk-main h1 { font-size: 1.7rem; margin: 0 0 18px; outline: none; border-radius: 6px; }
.bk-main h1:focus { background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: 0 0 0 2px var(--accent); }
.bk-content { min-height: 55vh; font-size: 1.04rem; line-height: 1.85; outline: none; }
.bk-content:focus { box-shadow: none; }
.bk-content p { margin: 0 0 1.1em; }
.bk-content:empty::before { content: attr(data-placeholder); color: var(--muted);
  font-style: italic; }
/* reading mode */
.bk-read { max-width: 700px; }
.bk-read-sema { font-family: var(--sans); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); }
.bk-read-beyit { background: var(--soft); border-radius: 10px; padding: 12px 16px;
  margin: 12px 0 20px; font-size: .93rem; }
.bk-read-beyit .badge { margin-top: 8px; display: inline-block; text-decoration: none; }
.bk-read-body { line-height: 1.85; font-size: 1.05rem; }
.bk-sema div, .bk-metaval, .bk-refno, .bk-beyit-tr, .bk-fa { outline: none; border-radius: 5px; }
.bk-sema div:focus, .bk-metaval:focus, .bk-refno:focus,
.bk-beyit-tr:focus, .bk-fa:focus {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: 0 0 0 2px var(--accent); }
[data-placeholder]:empty::before { content: attr(data-placeholder);
  color: var(--muted); opacity: .7; font-style: italic; }
.bk-beyit-head { display: flex; align-items: center; gap: 7px;
  font-family: var(--sans); font-size: .7rem; letter-spacing: .06em;
  text-transform: uppercase; margin-bottom: 4px; }
.bk-refno { font-weight: 700; color: var(--accent-ink); min-width: 18px;
  display: inline-block; }
.bk-beyit-head .badge { text-decoration: none; cursor: pointer; }
.bk-rowtools { display: none; gap: 3px; }
.bk-row:hover .bk-rowtools { display: inline-flex; }
.bk-rowtools button { padding: 1px 7px; font-size: .72rem; border-radius: 5px;
  background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.bk-rowtools button:hover { background: var(--accent); color: #fff; }
.nav-badge { display: inline-block; background: var(--warn); color: #fff;
  font-size: .62rem; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  margin-left: 4px; vertical-align: 1px; }
