@font-face { font-family: "KurdishSans"; src: url("fonts/noto-sans-arabic-arabic-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: "KurdishNaskh"; src: url("fonts/noto-naskh-arabic-arabic-wght-normal.woff2") format("woff2"); font-weight: 400 700; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
:root {
  --bg: #0f0f12; --panel: #17171c; --panel2: #1f1f26; --line: #2c2c36;
  --text: #ece8df; --muted: #8d8b95; --accent: #c9a35b; --accent-d: #a8853f; --danger: #e06c6c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; -webkit-text-size-adjust: 100%; }
button, input { font-family: inherit; }
body { background: var(--bg); color: var(--text); font: 15px/1.7 "KurdishSans", "Segoe UI", Tahoma, system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.center-text { text-align: center; margin-top: 60px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.login-card { width: min(380px, 100%); padding: 32px 28px; display: grid; gap: 14px; box-shadow: 0 20px 60px #0008; }
.login-card h1 { margin: 0; font-size: 22px; text-align: center; letter-spacing: .5px; }
.login-card p { margin: -8px 0 4px; text-align: center; font-size: 13px; }
.logo { width: 46px; height: 46px; margin: 0 auto; display: grid; place-items: center; border-radius: 12px;
  background: var(--accent); color: #111; font-size: 22px; }
.logo.sm { width: 28px; height: 28px; font-size: 14px; border-radius: 8px; margin: 0; display: inline-grid; }

label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input:not([type]), input[inputmode] {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }
input[type=file] { color: var(--muted); font-size: 13px; }
.captcha-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.captcha-q { background: var(--panel2); border: 1px dashed var(--accent-d); color: var(--accent);
  padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 17px; letter-spacing: 1px; user-select: none; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }

.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; font-size: 14px; cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--accent-d); }
.btn.primary { background: var(--accent); color: #17130a; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-d); }
.btn.icon { padding: 6px 11px; min-width: 38px; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: wait; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center;
  padding: 12px 20px; background: #0f0f12ee; backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.topbar input[type=search] { flex: 1; max-width: 420px; margin-inline-start: auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 22px; padding: 24px 20px 60px; max-width: 1400px; margin: 0 auto; }
.book { display: grid; gap: 8px; cursor: pointer; position: relative; }
.cover { aspect-ratio: 2/3; border-radius: 10px; overflow: hidden; background: var(--panel2);
  border: 1px solid var(--line); box-shadow: 0 8px 24px #0006; transition: transform .2s; display: grid; place-items: center; position: relative; }
.book:hover .cover { transform: translateY(-4px); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { padding: 14px; text-align: center; font-weight: 600; font-size: 15px; color: #fff; word-break: break-word; }
.badge { position: absolute; top: 8px; right: 8px; background: #000a; color: var(--accent); font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px; letter-spacing: .8px; }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.book .t { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .a { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book .meta { font-size: 12px; color: var(--muted); }
.menu { position: absolute; top: 6px; left: 6px; display: none; gap: 4px; }
.book:hover .menu { display: flex; }
.menu button { background: #000b; color: #fff; border: 0; border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.menu button:hover { background: var(--accent); color: #111; }
.menu button.del:hover { background: var(--danger); color: #fff; }

/* Reader */
#reader { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.reader-bar { position: static; }
.reader-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; flex: 1; }
.reader-title strong, .reader-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title span { font-size: 12px; }
.tools { display: flex; align-items: center; gap: 8px; }
.reader-body { flex: 1; overflow: auto; position: relative; background: #2a2a31; }
.pdf-page { position: relative; margin: 14px auto; background: #fff; box-shadow: 0 4px 20px #0007; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.html-frame { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.text-view { max-width: 760px; margin: 0 auto; padding: 36px 24px 80px; white-space: pre-wrap; word-wrap: break-word;
  font: 18px/2 "KurdishNaskh", "KurdishSans", Tahoma, serif; background: var(--bg); min-height: 100%; }
.other-view { display: grid; place-items: center; height: 100%; text-align: center; padding: 20px; background: var(--bg); }
.other-view a { text-decoration: none; display: inline-block; margin-top: 14px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(440px, 92vw); }
dialog::backdrop { background: #000a; backdrop-filter: blur(3px); }
.dlg { display: grid; gap: 14px; padding: 24px; }
.dlg h2 { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; }
progress { width: 100%; accent-color: var(--accent); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--accent-d);
  padding: 10px 18px; border-radius: 10px; z-index: 50; }


/* ---------- Responsive ---------- */
.reader-body { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.topbar { padding-inline: max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-left)); }
@media (hover: none) { .menu { display: flex; } .btn:hover { border-color: var(--line); } }
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  input, input[type=search], input[type=password] { font-size: 16px !important; } /* stops iOS zoom-on-focus */
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .brand { flex: 1; }
  .topbar input[type=search] { order: 5; flex-basis: 100%; max-width: none; margin: 0; }
  .btn { padding: 9px 12px; min-height: 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; padding: 14px 12px 40px; }
  .book .t { font-size: 14px; }
  .reader-bar { padding: 8px 10px; }
  .reader-title { flex-basis: 100%; order: 3; }
  #backBtn { order: 1; }
  .tools { order: 2; margin-inline-start: auto; }
  #rProgress { order: 2; font-size: 13px; }
  .pdf-page { margin: 8px auto; }
  .text-view { padding: 22px 16px 60px; }
  .login-card { padding: 26px 20px; }
  .dlg { padding: 18px; }
  .dlg-actions .btn { flex: 1; }
}
@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .captcha-row { grid-template-columns: 1fr; }
}
@media (min-width: 1500px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* touch: card actions sit at the bottom of the cover, never over the badge */
@media (hover: none), (max-width: 640px) {
  .menu { top: auto; bottom: 6px; left: 6px; right: 6px; justify-content: space-between; }
  .menu button { padding: 5px 9px; font-size: 12px; flex: 1; }
}
@media (max-width: 640px) {
  .brand { order: 1; flex: 1; }
  #logoutBtn { order: 2; }
  .topbar input[type=search] { order: 3; }
  #addBtn { order: 4; flex-basis: 100%; }
}
