/* ============ مكتبة مجلات سبيستون ============ */
:root {
  --bg-1: #0b0724;
  --bg-2: #171040;
  --bg-3: #241a5e;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #f2f0ff;
  --text-dim: #b6b0d8;
  --yellow: #ffd800;
  --cyan: #22c8f0;
  --magenta: #f0329b;
  --green: #55c81e;
  --orange: #ff8c1a;
  --grad-main: linear-gradient(135deg, var(--yellow), var(--orange), var(--magenta));
  --grad-cta: linear-gradient(135deg, #6a5cff, #22c8f0);
  --radius: 18px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Cairo', sans-serif;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 45%, var(--bg-3) 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select { font-family: 'Cairo', sans-serif; }

/* ---------- الأيقونات ---------- */
.icon {
  width: 18px; height: 18px;
  flex: 0 0 auto;
  vertical-align: -3px;
  fill: currentColor;
}
.icon-lg { width: 22px; height: 22px; }
.icon-heart { color: var(--magenta); width: 16px; height: 16px; }

/* ---------- خلفية النجوم ---------- */
.stars { position: fixed; inset: 0; z-index: -1; pointer-events: none; }

.stars-layer {
  position: absolute; inset: -100px;
  background-repeat: repeat;
  animation: twinkle 6s ease-in-out infinite alternate;
}
.stars-1 {
  background-image:
    radial-gradient(1.5px 1.5px at 30px 40px, #fff, transparent),
    radial-gradient(1px 1px at 120px 90px, #ffd800, transparent),
    radial-gradient(1.5px 1.5px at 200px 160px, #fff, transparent),
    radial-gradient(1px 1px at 280px 60px, #22c8f0, transparent);
  background-size: 320px 220px;
  opacity: .8;
}
.stars-2 {
  background-image:
    radial-gradient(1px 1px at 60px 130px, #fff, transparent),
    radial-gradient(2px 2px at 180px 30px, #f0329b, transparent),
    radial-gradient(1px 1px at 250px 190px, #fff, transparent);
  background-size: 300px 240px;
  animation-delay: -3s;
  opacity: .6;
}
.stars-3 {
  background-image:
    radial-gradient(1px 1px at 90px 200px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 220px 110px, #55c81e, transparent);
  background-size: 340px 260px;
  animation-delay: -1.5s;
  opacity: .5;
}
@keyframes twinkle { from { opacity: .35; } to { opacity: .9; } }

.nebula {
  position: absolute; border-radius: 50%;
  filter: blur(90px); opacity: .28;
}
.nebula-1 { width: 480px; height: 480px; top: -120px; left: -120px; background: #6a5cff; }
.nebula-2 { width: 420px; height: 420px; bottom: -100px; right: -100px; background: #f0329b; opacity: .18; }

/* ---------- الترويسة ---------- */
.hero {
  text-align: center;
  padding: 56px 20px 36px;
  position: relative;
}

.hero-logo {
  width: min(300px, 70vw);
  filter: drop-shadow(0 12px 34px rgba(34, 200, 240, .35));
  animation: float 5s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.hero-title {
  font-size: clamp(1.9rem, 5vw, 3.2rem);
  font-weight: 900;
  margin-top: 18px;
  letter-spacing: -.5px;
}
.grad-text {
  background: var(--grad-main);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  color: var(--text-dim);
  font-size: clamp(.95rem, 2.5vw, 1.15rem);
  margin-top: 8px;
  font-weight: 400;
}

.hero-gift {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 10px 24px;
  border-radius: 100px;
  background: rgba(255, 216, 0, .1);
  border: 1px solid rgba(255, 216, 0, .35);
  color: var(--yellow);
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 0 26px rgba(255, 216, 0, .15);
}
.hero-gift strong { font-weight: 900; }

.hero-games-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 24px;
  border-radius: 100px;
  background: rgba(34, 200, 240, .12);
  border: 1px solid rgba(34, 200, 240, .38);
  color: #7be8ff;
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 0 26px rgba(34, 200, 240, .13);
  transition: transform .2s, background .2s, border-color .2s;
}
.hero-games-link:hover {
  transform: translateY(-2px);
  background: rgba(34, 200, 240, .2);
  border-color: rgba(255, 216, 0, .48);
  color: var(--yellow);
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: clamp(16px, 5vw, 56px);
  margin-top: 36px;
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-num {
  font-size: clamp(1.8rem, 4.5vw, 2.6rem);
  font-weight: 900;
  background: var(--grad-cta);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.15;
}
.stat-label { color: var(--text-dim); font-size: .9rem; font-weight: 600; }

/* ---------- شريط الأدوات ---------- */
.toolbar-wrap {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 14px clamp(14px, 4vw, 40px) 6px;
  background: rgba(11, 7, 36, .82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto;
}

.search-box {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
}
.search-icon {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  color: var(--text-dim);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  border-radius: 100px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-box input::placeholder { color: var(--text-dim); font-weight: 400; }
.search-box input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(34, 200, 240, .15);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 10px 20px;
  border-radius: 100px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text-dim);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .22s;
}
.chip:hover { color: var(--text); border-color: rgba(255, 255, 255, .3); transform: translateY(-1px); }
.chip.active {
  background: var(--grad-cta);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(106, 92, 255, .4);
}

.adv-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 100px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text-dim);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .22s;
}
.adv-toggle:hover, .adv-toggle.open { color: var(--yellow); border-color: rgba(255, 216, 0, .4); }

.adv-panel {
  max-width: 1400px;
  margin: 0 auto;
  display: none;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 14px 4px 8px;
}
.adv-panel.open { display: flex; animation: slideDown .25s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.adv-field { display: flex; flex-direction: column; gap: 6px; }
.adv-field label { font-size: .8rem; font-weight: 700; color: var(--text-dim); }
.adv-field select, .adv-field input {
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--bg-2);
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  outline: none;
  min-width: 130px;
}
.adv-field input:focus, .adv-field select:focus { border-color: var(--cyan); }

.adv-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 12px;
  border: 1px solid rgba(240, 50, 155, .4);
  background: rgba(240, 50, 155, .1);
  color: var(--magenta);
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
}
.adv-reset:hover { background: rgba(240, 50, 155, .22); }

.results-count {
  max-width: 1400px;
  margin: 6px auto 0;
  color: var(--text-dim);
  font-size: .85rem;
  font-weight: 600;
  padding: 0 4px 6px;
}

/* ---------- الشبكة ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: clamp(14px, 2.5vw, 26px);
  padding: 28px clamp(14px, 4vw, 40px) 60px;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .3s cubic-bezier(.2, .8, .3, 1.2), box-shadow .3s, border-color .3s;
  animation: cardIn .45s ease backwards;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.card:hover {
  transform: translateY(-8px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .55), 0 0 0 1px rgba(34, 200, 240, .35);
  border-color: transparent;
}

.card-cover {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: linear-gradient(120deg, rgba(255,255,255,.05) 25%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.05) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite;
  cursor: pointer;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.card-cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .45s ease;
  opacity: 0;
}
.card-cover img.loaded { opacity: 1; }
.card:hover .card-cover img { transform: scale(1.06); }

.card-cover .cover-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11, 7, 36, .55);
  opacity: 0;
  transition: opacity .3s;
  backdrop-filter: blur(2px);
}
.card:hover .cover-overlay { opacity: 1; }
.cover-overlay span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 100px;
  background: var(--grad-cta);
  font-weight: 800;
  font-size: .95rem;
  color: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .4);
}

.badge {
  position: absolute;
  top: 10px; right: 10px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 800;
  color: #0b0724;
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.badge-main { background: var(--yellow); }
.badge-fatayat { background: linear-gradient(135deg, #ff9ecb, var(--magenta)); color: #fff; }

.card-body {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.card-title { font-size: 1.02rem; font-weight: 800; line-height: 1.3; }
.card-meta { font-size: .78rem; color: var(--text-dim); font-weight: 600; }

.card-actions { display: flex; gap: 8px; margin-top: auto; }
.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 12px;
  border: none;
  font-size: .87rem;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s, filter .2s, box-shadow .2s;
}
.btn:active { transform: scale(.96); }
.btn-preview {
  background: var(--grad-cta);
  color: #fff;
  box-shadow: 0 6px 18px rgba(106, 92, 255, .35);
}
.btn-preview:hover { filter: brightness(1.15); }
.btn-download {
  background: rgba(85, 200, 30, .15);
  color: #8ce85a;
  border: 1px solid rgba(85, 200, 30, .4);
}
.btn-download:hover { background: rgba(85, 200, 30, .3); }

/* ---------- حالة فارغة ---------- */
.empty {
  text-align: center;
  padding: 70px 20px 110px;
}
.empty-icon {
  width: 72px; height: 72px;
  color: var(--text-dim);
  opacity: .6;
  margin-bottom: 12px;
  animation: float 4s ease-in-out infinite;
}
.empty h3 { font-size: 1.5rem; font-weight: 900; }
.empty p { color: var(--text-dim); margin-top: 6px; }

/* ---------- ترقيم الصفحات ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 20px 70px;
}
.pagination:empty { padding: 0 0 30px; }
.page-btn {
  min-width: 44px; height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.page-btn:hover:not(:disabled) {
  border-color: var(--cyan);
  background: rgba(34, 200, 240, .12);
  transform: translateY(-2px);
}
.page-btn:disabled:not(.active) { opacity: .35; cursor: default; }
.page-btn.active {
  background: var(--grad-cta);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px rgba(106, 92, 255, .4);
  cursor: default;
}
.page-dots { color: var(--text-dim); font-weight: 800; padding: 0 2px; }

/* ---------- التذييل ---------- */
.footer {
  text-align: center;
  padding: 44px 20px 56px;
  border-top: 1px solid rgba(255, 255, 255, .07);
  background: rgba(0, 0, 0, .22);
}
.footer-logo { width: 130px; opacity: .9; }
.footer-gift { margin-top: 14px; font-size: 1.05rem; font-weight: 700; }
.footer-gift strong { color: var(--yellow); font-weight: 900; }
.footer-note { color: var(--text-dim); font-size: .85rem; margin-top: 6px; }

/* ---------- نافذة المعاينة ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 3, 18, .82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-box {
  position: relative;
  width: min(960px, 96vw);
  height: min(92vh, 1000px);
  background: var(--bg-2);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn .3s cubic-bezier(.2, .9, .3, 1.15);
}
@keyframes modalIn { from { opacity: 0; transform: scale(.92) translateY(20px); } to { opacity: 1; transform: none; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .03);
}
.modal-title { font-size: 1.05rem; font-weight: 900; }
.modal-actions { display: flex; align-items: center; gap: 10px; }
.modal-actions .btn-download { flex: 0 0 auto; padding: 9px 16px; }

.btn-close {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.btn-close:hover { background: rgba(240, 50, 155, .25); border-color: var(--magenta); }

.viewer {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #0a0620;
  display: flex;
}
.canvas-wrap {
  margin: auto;
  padding: 18px;
  display: flex;
}
#pdfCanvas {
  border-radius: 6px;
  box-shadow: 0 12px 44px rgba(0, 0, 0, .6);
  max-width: none;
}

.viewer-loading {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  font-weight: 700;
  background: #0a0620;
  z-index: 3;
}
.viewer-loading[hidden] { display: none; }
.spinner {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .12);
  border-top-color: var(--cyan);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .03);
}
.vgroup { display: inline-flex; align-items: center; gap: 8px; }
.vbtn {
  min-width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.vbtn .icon { width: 20px; height: 20px; }
.vbtn:hover:not(:disabled) { background: rgba(106, 92, 255, .35); border-color: #6a5cff; }
.vbtn:disabled { opacity: .35; cursor: default; }

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-weight: 800;
  font-size: .92rem;
}
.page-jump input {
  width: 58px;
  height: 42px;
  text-align: center;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--bg-1);
  color: var(--text);
  font-size: .95rem;
  font-weight: 800;
  outline: none;
  -moz-appearance: textfield;
}
.page-jump input::-webkit-outer-spin-button,
.page-jump input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.page-jump input:focus { border-color: var(--cyan); }

.zoom-info { font-weight: 800; font-size: .92rem; color: var(--text-dim); min-width: 52px; text-align: center; }
.vsep { width: 1px; height: 24px; background: rgba(255, 255, 255, .12); margin: 0 6px; }

/* ---------- استجابة ---------- */
@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .card-actions { flex-direction: column; }
  .hero { padding-top: 40px; }
  .adv-panel .adv-field { flex: 1 1 40%; }
  .adv-field select, .adv-field input { min-width: 0; width: 100%; }
  .page-btn { min-width: 40px; height: 40px; font-size: .9rem; }

  /* المعاينة على الجوال */
  .modal-box { width: 100vw; height: 100dvh; border-radius: 0; border: none; }
  .modal-head { padding: 10px 12px; }
  .modal-title { font-size: .88rem; }
  .modal-actions { gap: 6px; }
  .modal-actions .btn-download { padding: 8px 10px; font-size: .78rem; }
  .modal-actions .btn-label { display: none; }
  .canvas-wrap { padding: 8px; }
  .viewer-bar { gap: 6px; padding: 8px 6px; }
  .vgroup { gap: 5px; }
  .vbtn { min-width: 40px; height: 40px; }
  .page-jump input { width: 48px; height: 40px; }
  .vsep { display: none; }
}
