/**
 * قارئ المستندات – نمط كتاب/جريدة
 * يعمل على الجوال والكمبيوتر – بدون سحب عمودي، تقليب الصفحات فقط
 */

:root {
  --reader-bg: #1a1612;
  --reader-surface: #252019;
  --reader-ink: #f5f0e8;
  --reader-ink-soft: #a89f8f;
  --reader-accent: #c9a227;
  --reader-accent-hover: #ddb83a;
  --reader-header-height: 52px;
  --reader-footer-height: 56px;
  --reader-safe-top: env(safe-area-inset-top, 0);
  --reader-safe-bottom: env(safe-area-inset-bottom, 0);
  --reader-ease: cubic-bezier(0.35, 0, 0.15, 1);
  --reader-flip-duration: 0.35s;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body.reader-body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: var(--reader-bg);
  color: var(--reader-ink);
  font-family: 'Tajawal', sans-serif;
  -webkit-overflow-scrolling: touch;
  -webkit-user-select: none;
  user-select: none;
  touch-action: pan-x;
}

.reader-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  min-height: -webkit-fill-available;
  padding-top: var(--reader-safe-top);
  padding-bottom: var(--reader-safe-bottom);
  overflow: hidden;
}

.reader-header {
  flex-shrink: 0;
  height: var(--reader-header-height);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--reader-surface);
  border-bottom: 1px solid rgba(201, 162, 39, 0.2);
}

.reader-back {
  color: var(--reader-accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 4px;
}

.reader-title {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-align: center;
}

.reader-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--reader-ink);
  font-size: 1.25rem;
  cursor: pointer;
}

.reader-btn--search { background: rgba(201, 162, 39, 0.15); }
.reader-btn:active { opacity: 0.8; }

/* منطقة العرض – بدون أي سحب عمودي */
.reader-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-x;
}

.reader-book {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.reader-page-slot {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--reader-flip-duration) var(--reader-ease), opacity var(--reader-flip-duration) var(--reader-ease);
}

.reader-page-slot.flip-next {
  transform: translateX(100%);
  opacity: 0;
}

.reader-page-slot.flip-prev {
  transform: translateX(-100%);
  opacity: 0;
}

.reader-page-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.reader-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  background: #fff;
}

.reader-spread {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.reader-canvas--half {
  max-width: calc(50% - 8px);
  max-height: 100%;
  flex: 1;
}

.reader-spine {
  width: 8px;
  flex-shrink: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.12) 100%);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(0,0,0,0.15);
}

.reader-footer {
  flex-shrink: 0;
  height: var(--reader-footer-height);
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--reader-surface);
  border-top: 1px solid rgba(201, 162, 39, 0.2);
}

.reader-nav-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(201, 162, 39, 0.2);
  color: var(--reader-accent);
  font-size: 1.4rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.reader-nav-btn:active {
  transform: scale(0.95);
  background: rgba(201, 162, 39, 0.35);
}

.reader-page-info {
  min-width: 72px;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
}

.reader-page-sep { color: var(--reader-ink-soft); margin: 0 2px; }

.reader-mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 24px;
  background: transparent;
  color: var(--reader-accent);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.reader-mode-btn:active { background: rgba(201, 162, 39, 0.15); }
.reader-mode-icon { font-size: 1rem; }

/* لوحة البحث */
.reader-search-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--reader-bg);
  display: flex;
  flex-direction: column;
  padding-top: var(--reader-safe-top);
  padding-bottom: var(--reader-safe-bottom);
  transform: translateY(-100%);
  transition: transform 0.3s var(--reader-ease);
}

.reader-search-panel.is-open { transform: translateY(0); }

.reader-search-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--reader-surface);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.reader-search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 12px;
  background: var(--reader-bg);
  color: var(--reader-ink);
  font-family: inherit;
  font-size: 1rem;
}

.reader-search-input:focus { outline: none; border-color: var(--reader-accent); }
.reader-search-close {
  width: 44px; height: 44px;
  border: none; border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: var(--reader-ink);
  font-size: 1.2rem;
  cursor: pointer;
}

.reader-search-results {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

.reader-search-result-item {
  display: block;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--reader-surface);
  border-radius: 12px;
  color: var(--reader-ink);
  text-decoration: none;
  font-size: 0.95rem;
  border: 1px solid transparent;
}

.reader-search-result-item:active,
.reader-search-result-item:hover {
  background: rgba(201, 162, 39, 0.1);
  border-color: rgba(201, 162, 39, 0.3);
}

.reader-search-result-page {
  display: block;
  font-size: 0.8rem;
  color: var(--reader-accent);
  margin-top: 4px;
}

.reader-search-status {
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--reader-ink-soft);
  text-align: center;
}

.reader-loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--reader-bg);
  padding: 24px;
}

.reader-error {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--reader-bg);
  padding: 12px;
  padding-top: var(--reader-safe-top);
  padding-bottom: var(--reader-safe-bottom);
}

.reader-loading.hidden,
.reader-error.hidden { display: none !important; }

.reader-error-msg {
  flex-shrink: 0;
  text-align: center;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.reader-error-msg p {
  margin: 0;
}
.reader-error-hint {
  font-size: 0.9rem;
  color: var(--reader-muted, #888);
  margin-top: 8px !important;
}
.reader-error-hint code {
  background: rgba(0,0,0,.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.reader-error-link {
  color: var(--reader-accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.reader-error-link--primary {
  display: inline-block;
  padding: 10px 20px;
  background: rgba(201, 162, 39, 0.2);
  border-radius: 10px;
  border: 1px solid var(--reader-accent);
}

.reader-error-iframe {
  flex: 1;
  min-height: 400px;
  width: 100%;
  border: none;
  border-radius: 8px;
  background: #fff;
}

.reader-loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(201, 162, 39, 0.3);
  border-top-color: var(--reader-accent);
  border-radius: 50%;
  animation: reader-spin 0.9s linear infinite;
}

@keyframes reader-spin { to { transform: rotate(360deg); } }
.reader-loading-text { margin: 0; color: var(--reader-ink-soft); }

@supports (-webkit-touch-callout: none) {
  body.reader-body { min-height: -webkit-fill-available; }
  .reader-app { min-height: -webkit-fill-available; }
}
