:root {
  --bg-deep: #0c2a22;
  --bg-mid: #134235;
  --gold: #c9a24a;
  --gold-soft: #e3c77e;
  --paper: #fbf5e6;
  --paper-edge: #efe2bf;
  --ink: #2b2118;
  --ink-soft: #6b5a45;
  --accent: #1f7a4a; /* overridden per book */
  --radius: 6px;
  /* Persian only — never add letter-spacing or italics to Persian text (breaks letter joining) */
  --font: "Vazirmatn", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.05rem;
  line-height: 1.9;
}

/* ---------- Fixed background ----------
   A pseudo-element instead of background-attachment: fixed,
   because iOS Safari ignores that property.
   assets/pattern.svg is a seamless Flower of Life tile (overlapping circles,
   no star shapes) — edit its stroke colour/opacity to restyle. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    url("../assets/pattern.svg") center / 120px auto,
    radial-gradient(ellipse at 50% 20%, var(--bg-mid) 0%, var(--bg-deep) 70%, #06140f 100%);
}

/* ---------- Night sky (twinkles, drifting glow, meteors) ----------
   Sits above the pattern (later in the DOM, same z-index) and below the page.
   Glows are placed on the pattern's own dots by js/sky.js — never add extra dots. */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

/* soft light slowly drifting across the sky */
.sky::before {
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(circle at 30% 30%, rgba(227, 199, 126, 0.10), transparent 35%),
    radial-gradient(circle at 70% 65%, rgba(140, 220, 190, 0.07), transparent 40%);
  animation: drift 40s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate(-6%, -4%); }
  to   { transform: translate(6%, 5%); }
}

/* Glow placed exactly on a pattern dot (positions from js/sky.js).
   Invisible most of the cycle, so the existing dot just flares up briefly. */
.twinkle {
  position: absolute;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px; /* centre on the dot */
  border-radius: 50%;
  background: #fff4cf;
  box-shadow: 0 0 6px 2px rgba(227, 199, 126, 0.75), 0 0 14px 4px rgba(227, 199, 126, 0.25);
  opacity: 0;
  animation: twinkle ease-in-out infinite;
}
@keyframes twinkle {
  0%, 70%, 100% { opacity: 0; transform: scale(0.4); }
  85%           { opacity: 1; transform: scale(1); }
}

.meteor {
  position: absolute;
  width: 140px;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 251, 233, 0.9), transparent);
  border-radius: 1px;
  transform: rotate(155deg);
  transform-origin: left center;
  animation: meteor 1.4s ease-out forwards;
}
@keyframes meteor {
  0%   { opacity: 0; translate: 0 0; }
  15%  { opacity: 1; }
  100% { opacity: 0; translate: -260px 120px; }
}

/* ---------- Center page ---------- */
.page {
  width: min(960px, calc(100% - 32px));
  margin: 40px auto;
  background: var(--paper);
  border: 1px solid var(--gold);
  outline: 6px double var(--gold);
  outline-offset: 6px;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  padding: 32px clamp(18px, 5vw, 56px) 24px;
}

.ornament {
  text-align: center;
  color: var(--gold);
  font-size: 1.4rem;
  letter-spacing: 1em;
}

.page-header { text-align: center; }

.name {
  margin: 8px 0 0;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1.4;
}

.tagline {
  margin: 4px 0 20px;
  color: var(--ink-soft);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  padding: 10px 0;
  border-block: 1px solid var(--paper-edge);
}

.nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}
.nav a:hover { background: var(--paper-edge); }
.nav a[aria-current] { background: var(--bg-mid); color: var(--gold-soft); }
.nav a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Swappable view ---------- */
.view {
  padding: 28px 0 12px;
  outline: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.view.leaving { opacity: 0; transform: translateY(6px); }

h2 { font-size: 1.7rem; margin: 0 0 8px; line-height: 1.5; }
h3 { font-size: 1.25rem; margin: 24px 0 6px; }
a { color: var(--bg-mid); }

.intro { text-align: center; margin-bottom: 28px; }

/* ---------- Home: book cards ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
}

.book-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--paper-edge);
  border-top: 5px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.book-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15); }
.book-card img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.book-card-body { display: flex; flex-direction: column; padding: 14px 16px 18px; text-align: center; }
.book-card .title { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.book-card .count { font-size: 0.95rem; color: var(--ink-soft); }

/* ---------- Book page ---------- */
.book-head {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 24px;
  align-items: center;
  margin-bottom: 24px;
}
.book-cover {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.book-head h2 { color: var(--accent); margin: 0; }
.book-head .subtitle { margin: 0; color: var(--ink-soft); }

.player {
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--accent);
}
.player video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.now-playing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.lessons { list-style: none; padding: 0; margin: 20px 0 0; }
.lessons a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--paper-edge);
  border-radius: var(--radius);
}
.lessons a:hover { background: var(--paper-edge); }
.lessons a[aria-current] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.lessons .title { font-weight: 600; }

.num {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid currentColor;
  font-size: 0.95rem;
}

.empty { color: var(--ink-soft); }

/* ---------- Footer ---------- */
.page-footer {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--paper-edge);
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.95rem;
}
.page-footer p { margin: 4px 0 0; }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  .page { margin: 20px auto; outline-offset: 3px; outline-width: 4px; padding-top: 22px; }

  /* Header: tighter rhythm so the name, tagline and nav read as one block */
  .ornament { font-size: 1.1rem; }
  .name { margin-top: 2px; }
  .tagline { margin: 0 0 14px; font-size: 0.95rem; }

  /* Nav: one row of evenly spread links instead of wrapping onto a second line.
     If a future label makes it too wide, the row scrolls sideways rather than wrapping. */
  .nav {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 2px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 1 0 auto;
    text-align: center;
    white-space: nowrap;
    padding: 4px 10px;
    font-size: 0.95rem;
  }

  .book-head { grid-template-columns: 90px 1fr; gap: 16px; }
  h2 { font-size: 1.6rem; }
}

/* Smallest phones (iPhone SE and similar): keep all four links on screen */
@media (max-width: 380px) {
  .page { padding-inline: 14px; }
  .nav a { padding: 4px 7px; font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
  .sky::before, .twinkle { animation: none; }
}
