:root {
  --text: #eef4ff;
  --muted: #9bb0d0;
  --glass: rgba(10, 14, 34, 0.72);
  --stroke: rgba(255, 255, 255, 0.12);
  --a1: #a855f7;
  --a2: #67e8f9;
  --a3: #f59e0b;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --info: #38bdf8;
  --bg0: #07051a;
  --font: "Exo 2", system-ui, sans-serif;
  --display: "Sora", system-ui, sans-serif;
  --page-bg: #fffdf8;
  --page-text: #1e293b;
  --page-muted: #64748b;
  --page-accent: #5b21b6;
  --page-accent2: #0891b2;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg0);
  overflow-x: hidden;
}

.manual-view-only,
.manual-view-only .book-page,
.manual-view-only .page-inner {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.manual-view-only img {
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

.nebula {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(168, 85, 247, 0.22), transparent 42%),
    radial-gradient(ellipse at 80% 0%, rgba(103, 232, 249, 0.14), transparent 40%),
    radial-gradient(ellipse at 50% 80%, rgba(56, 189, 248, 0.08), transparent 45%);
}

.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 35%, transparent 32%, rgba(0, 0, 0, 0.5) 100%);
}

/* ── Top bar ─────────────────────────────────────────────── */

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px clamp(12px, 3vw, 28px); height: 64px;
  background: rgba(8, 12, 28, 0.92); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--stroke);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 10px; object-fit: contain; }
.brand b { font-family: var(--display); font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.brand small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn-ghost {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--stroke); transition: background 0.15s, border-color 0.15s;
}
.btn-ghost:hover { border-color: rgba(168, 85, 247, 0.5); background: rgba(168, 85, 247, 0.1); }

.view-only-badge {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.12);
}

.lang-select {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.manual-rtl .page-inner th { text-align: right; }
.manual-rtl .page-inner ul,
.manual-rtl .page-inner ol { padding-right: 1.25rem; padding-left: 0; }
.manual-rtl .page-figure::after { right: auto; left: 10px; }
.manual-rtl .book-page.is-current { transform: translateX(0); }
.manual-rtl .book-page { transform: translateX(-24px); }
.manual-rtl .book-page.is-behind { transform: translateX(24px); }
.manual-rtl .book-page.is-slide-out-left { transform: translateX(40px); }
.manual-rtl .book-page.is-slide-out-right { transform: translateX(-40px); }
.manual-rtl .toc-page li { border-left: none; border-right: 4px solid var(--page-accent); }
.manual-rtl .callout--info,
.manual-rtl .callout--tip,
.manual-rtl .callout--warn { border-left: none; border-right-width: 4px; border-right-style: solid; }
.manual-rtl .callout--info { border-right-color: var(--page-accent); }
.manual-rtl .callout--tip { border-right-color: var(--ok); }
.manual-rtl .callout--warn { border-right-color: var(--warn); }
.manual-rtl body,
.manual-rtl .page-inner { font-family: "Noto Sans Arabic", var(--font); }

.btn-login {
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 700;
  color: #041018; background: linear-gradient(135deg, var(--a2), var(--a1));
  box-shadow: 0 8px 24px rgba(168, 85, 247, 0.3);
}

/* ── Stage ───────────────────────────────────────────────── */

.stage {
  position: relative; z-index: 2;
  min-height: 100vh; padding: 84px 12px 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}

.book-hint {
  font-size: 13px; color: var(--muted); text-align: center;
  animation: fadeHint 4s ease 2s forwards;
}
@keyframes fadeHint { to { opacity: 0.35; } }

/* ── Book shell ──────────────────────────────────────────── */

.book-shell {
  position: relative;
  width: min(920px, 96vw);
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 0;
}

.book-frame {
  position: relative;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.38));
}

.book-frame::before {
  content: "";
  position: absolute;
  inset: 6%;
  z-index: -1;
  border-radius: 16px;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 42%,
    rgba(168, 85, 247, 0.16) 0%,
    rgba(103, 232, 249, 0.07) 42%,
    transparent 68%
  );
  filter: blur(14px);
}

.book-pages {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 420px;
  max-height: min(72vh, 640px);
}

/* ── Individual page (single-page slide, not a book spread) ── */

.book-page {
  position: absolute; inset: 0;
  background: var(--page-bg);
  color: var(--page-text);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(0, 0, 0, 0.14);
  transition: transform 0.35s ease, opacity 0.35s ease;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transform: translateX(24px);
}

.book-page.is-current {
  opacity: 1;
  pointer-events: auto;
  z-index: 10;
  transform: translateX(0);
}

.book-page.is-behind {
  opacity: 0;
  z-index: 0;
  transform: translateX(-24px);
}

.book-page.is-slide-out-left {
  z-index: 5;
  opacity: 0;
  transform: translateX(-40px);
}

.book-page.is-slide-out-right {
  z-index: 5;
  opacity: 0;
  transform: translateX(40px);
}

.book-page.is-slide-in {
  z-index: 10;
  opacity: 1;
  transform: translateX(0);
  animation: slideIn 0.35s ease;
}

@keyframes slideIn {
  from { opacity: 0.4; transform: translateX(32px); }
  to { opacity: 1; transform: translateX(0); }
}

.page-inner {
  height: 100%;
  overflow-y: auto;
  padding: clamp(20px, 3.5vw, 32px);
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}

.page-inner::-webkit-scrollbar { width: 6px; }
.page-inner::-webkit-scrollbar-thumb { background: #c4b5fd; border-radius: 3px; }

/* ── Page types ──────────────────────────────────────────── */

.page-cover {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; min-height: 100%;
  background: linear-gradient(145deg, #0f172a 0%, #1e1b4b 40%, #4c1d95 100%);
  color: #fff; padding: 40px 28px !important;
}

.page-cover::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 25%, rgba(168, 85, 247, 0.35), transparent 45%),
    radial-gradient(circle at 80% 75%, rgba(56, 189, 248, 0.25), transparent 40%);
  pointer-events: none;
}

.page-cover > * { position: relative; z-index: 1; }

.page-cover .cover-logo {
  width: 72px; height: 72px; border-radius: 18px; margin-bottom: 24px;
  box-shadow: 0 12px 40px rgba(168, 85, 247, 0.45);
}

.page-cover .cover-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase;
  padding: 8px 18px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.25);
  color: #e9d5ff; margin-bottom: 28px;
}

.page-cover h1 {
  font-family: var(--display); font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 800; line-height: 1.05; margin-bottom: 10px;
}

.page-cover h1 span {
  display: block; font-size: 1.15em;
  background: linear-gradient(90deg, #c4b5fd, #67e8f9, #6ee7b7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.page-cover .cover-sub { font-size: 1.1rem; color: #cbd5e1; margin-bottom: 6px; }
.page-cover .cover-meta { font-size: 0.95rem; color: #94a3b8; }

.page-back {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; min-height: 100%;
  background: linear-gradient(160deg, #312e81, #1e1b4b);
  color: #e2e8f0; padding: 40px !important;
}

.page-back h2 { font-family: var(--display); font-size: 1.8rem; margin-bottom: 12px; color: #c4b5fd; }
.page-back p { font-size: 1rem; color: #94a3b8; max-width: 36ch; line-height: 1.6; }

/* ── Content typography ──────────────────────────────────── */

.page-chapter {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: #fff; background: linear-gradient(90deg, var(--page-accent), #7c3aed);
  padding: 6px 12px; border-radius: 6px; margin-bottom: 10px;
}

.page-inner h2 {
  font-family: var(--display);
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 800; color: var(--page-accent);
  margin-bottom: 12px; line-height: 1.2;
}

.page-inner h3 {
  font-size: 1rem; font-weight: 700; color: var(--page-accent2);
  margin: 16px 0 8px; padding-bottom: 4px;
  border-bottom: 2px solid #e9d5ff;
}

.page-inner p, .page-inner li {
  font-size: clamp(0.88rem, 1.8vw, 0.98rem);
  line-height: 1.6; color: var(--page-text); margin-bottom: 10px;
}

.page-inner ul, .page-inner ol { padding-left: 1.25rem; margin-bottom: 12px; }
.page-inner li { margin-bottom: 5px; }
.page-inner strong { color: var(--page-accent); font-weight: 700; }

.page-inner table {
  width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.82rem;
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.page-inner th {
  background: linear-gradient(90deg, #5b21b6, #7c3aed);
  color: #fff; text-align: left; padding: 8px 10px; font-weight: 700;
}

.page-inner td {
  padding: 7px 10px; border-bottom: 1px solid #e2e8f0; vertical-align: top;
}

.page-inner tr:nth-child(even) td { background: #f8fafc; }

.page-figure {
  position: relative;
  margin: 14px 0; border-radius: 10px; overflow: hidden;
  border: 2px solid #e9d5ff;
  box-shadow: 0 8px 24px rgba(91, 33, 182, 0.15);
}

.page-figure::after {
  content: "View only";
  position: absolute;
  right: 10px;
  bottom: 34px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(15, 23, 42, 0.55);
  pointer-events: none;
}

.page-figure img {
  display: block; width: 100%; height: auto; max-height: 200px;
  object-fit: cover; object-position: top center;
}

.page-figure figcaption {
  font-size: 11px; font-weight: 600; color: var(--page-muted);
  padding: 6px 10px; background: #f5f3ff; text-align: center;
}

.callout {
  border-radius: 10px; padding: 12px 14px; margin: 12px 0;
  font-size: 0.88rem; line-height: 1.55;
}

.callout--tip {
  background: linear-gradient(135deg, #ecfdf5, #ecfeff);
  border-left: 4px solid var(--ok); color: #065f46;
}

.callout--info {
  background: linear-gradient(135deg, #f5f3ff, #ede9fe);
  border-left: 4px solid var(--page-accent); color: #4c1d95;
}

.callout--warn {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border-left: 4px solid var(--warn); color: #92400e;
}

.callout strong { color: inherit; }

.toc-page ol {
  list-style: none; padding: 0; columns: 1;
}

.toc-page li {
  margin: 0 0 8px; padding: 10px 12px; border-radius: 8px;
  background: linear-gradient(90deg, #f5f3ff, #ecfeff);
  border-left: 4px solid var(--page-accent);
  font-weight: 600; font-size: 0.92rem; color: #3730a3;
  cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}

.toc-page li:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(91, 33, 182, 0.15);
}

.toc-page li span { color: #7c3aed; font-weight: 800; margin-right: 6px; }

/* ── Turn zones & pager ──────────────────────────────────── */

.turn-zone {
  width: 48px; height: 120px; border-radius: 8px;
  opacity: 0.5; transition: opacity 0.15s, background 0.15s;
}
.turn-zone:hover { opacity: 1; background: rgba(168, 85, 247, 0.12); }

.pager {
  display: flex; align-items: center; gap: 16px;
}

.pager-btn {
  width: 44px; height: 44px; border-radius: 50%;
  font-size: 24px; line-height: 1; font-weight: 300;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  transition: background 0.15s, transform 0.12s;
}
.pager-btn:hover:not(:disabled) { background: rgba(168, 85, 247, 0.2); transform: scale(1.05); }
.pager-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.pager-label { font-size: 14px; font-weight: 600; color: var(--muted); min-width: 120px; text-align: center; }

/* ── TOC dialog ──────────────────────────────────────────── */

.toc-dialog {
  border: 1px solid var(--stroke); border-radius: 16px; padding: 0;
  background: rgba(12, 16, 36, 0.96); color: var(--text);
  max-width: 480px; width: calc(100% - 32px);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5);
}
.toc-dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }

.toc-dialog__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--stroke);
}
.toc-dialog__head h2 { font-family: var(--display); font-size: 1.25rem; }

.toc-close {
  width: 36px; height: 36px; border-radius: 50%; font-size: 22px;
  border: 1px solid var(--stroke);
}
.toc-close:hover { background: rgba(255, 255, 255, 0.08); }

.toc-list {
  list-style: none; padding: 16px 20px 20px; max-height: 60vh; overflow-y: auto;
}

.toc-list li {
  padding: 10px 12px; margin-bottom: 6px; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: background 0.12s, border-color 0.12s;
}
.toc-list li:hover {
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.3);
}
.toc-list li span { color: var(--a2); margin-right: 8px; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 700px) {
  .book-shell { grid-template-columns: 1fr; }
  .turn-zone { display: none; }
  .book-pages { min-height: 380px; max-height: 65vh; }
  .topbar-actions .btn-ghost { display: none; }
  .topbar-actions .view-only-badge { font-size: 10px; padding: 6px 8px; }
  .page-figure img { max-height: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  .book-page { transition: none; }
  .book-page.is-slide-in { animation: none; }
}
