:root {
  --sky-1: #241242;
  --sky-2: #3a1d5e;
  --sky-3: #4a2168;
  --paper: #fdf6e9;
  --paper-2: #f6ead2;
  --paper-line: #e8d5ad;
  --ink: #3a2a1e;
  --ink-soft: #7a6650;
  --gold: #f4b942;
  --gold-deep: #d98e2b;
  --rose: #ff6f91;
  --teal: #3fc8b4;
  --violet: #9d7bff;
  --shadow-lg: 0 22px 60px -18px rgba(15, 6, 34, .7);
  --shadow-md: 0 12px 30px -12px rgba(15, 6, 34, .55);
  --radius: 26px;
  --radius-sm: 16px;
  --font-display: "Fredoka", "Varela Round", system-ui, sans-serif;
  --font-body: "Varela Round", "Fredoka", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--sky-1); scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  direction: rtl;
  font-family: var(--font-body);
  color: var(--paper);
  background: radial-gradient(140% 120% at 50% -10%, var(--sky-3), var(--sky-2) 45%, var(--sky-1) 100%);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.stars {
  position: absolute;
  inset: -20%;
  background-repeat: repeat;
}

.stars--far {
  background-image:
    radial-gradient(1.4px 1.4px at 20% 30%, #fff8 40%, transparent),
    radial-gradient(1.2px 1.2px at 70% 60%, #fff6 40%, transparent),
    radial-gradient(1px 1px at 40% 80%, #fff5 40%, transparent),
    radial-gradient(1.3px 1.3px at 88% 22%, #fff7 40%, transparent);
  background-size: 340px 340px;
  opacity: .8;
}

.stars--near {
  background-image:
    radial-gradient(2px 2px at 15% 65%, var(--gold) 40%, transparent),
    radial-gradient(1.6px 1.6px at 82% 78%, #fff 40%, transparent),
    radial-gradient(2.2px 2.2px at 60% 40%, var(--gold) 40%, transparent);
  background-size: 520px 520px;
  opacity: .8;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .45;
}

.orb--gold { width: 260px; height: 260px; top: -40px; right: -60px; background: var(--gold); }
.orb--rose { width: 220px; height: 220px; bottom: 10%; left: -70px; background: var(--rose); }
.orb--teal { width: 180px; height: 180px; top: 45%; right: -50px; background: var(--teal); opacity: .32; }

.moon {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e7, #f4e2b0 70%, #e6cf8f);
  box-shadow: 0 0 40px 8px rgba(244, 226, 176, .45), inset -8px -6px 0 rgba(0,0,0,.04);
}

.page {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 54px;
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  margin: -14px 0 14px;
}
/* full-bleed scrim behind the sticky topbar (regardless of the page's own
   centered max-width) so content scrolling underneath — and the decorative
   moon — never wash out the brand mark or the sign-in pill's translucent
   background */
.topbar::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 100vw;
  transform: translateX(-50%);
  background: rgba(20, 10, 38, .72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,.06);
  z-index: -1;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand img {
  width: 58px;
  height: 58px;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.22));
}

.brand__text {
  display: grid;
  gap: 2px;
}

.brand__name {
  font-family: var(--font-display);
  font-size: clamp(21px, 4vw, 31px);
  font-weight: 700;
}

.brand__sub {
  color: #ccbce9;
  font-size: 13px;
}

.nav-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-link,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  padding: 10px 18px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.08);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 10px 24px -18px rgba(0,0,0,.6);
}

.button {
  border: none;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--sky-1);
  box-shadow: 0 12px 28px -12px rgba(244, 185, 66, .9);
}

.nav-actions [hidden] { display: none; }

/* account slot: nav links + coin badge/sign-in pinned together at the far
   (left) end of the topbar — the coin badge always opens #account-menu. */
.site-header__account {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.site-header__account [hidden] { display: none; }

.coin-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--sky-1);
  font-family: var(--font-display);
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 12px 28px -12px rgba(244, 185, 66, .9);
  transition: transform .2s ease;
}
.coin-badge:hover { transform: translateY(-2px); }
.coin-badge__chevron { font-size: 10px; opacity: .8; transform: translateY(1px); }

.coin-svg { width: 20px; height: 20px; vertical-align: middle; }

/* ============ ACCOUNT DROPDOWN (off the coin badge) ============ */
.pmenu { position: fixed; inset: 0; z-index: 70; }
.pmenu[hidden] { display: none; }
.pmenu__backdrop { position: absolute; inset: 0; } /* transparent — outside click closes */
.pmenu__panel {
  position: absolute; top: 78px; inset-inline-start: 18px;
  width: min(280px, calc(100vw - 28px));
  background: var(--paper); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 14px; text-align: start; color: var(--ink);
}
.pmenu__head {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 6px 12px; border-bottom: 1px solid var(--paper-line);
}
.pmenu__avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.pmenu__id { min-width: 0; }
.pmenu__name {
  font-family: var(--font-display); font-weight: 700; color: var(--ink); font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pmenu__email {
  color: var(--ink-soft); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pmenu__row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: start; border: none; background: transparent; cursor: pointer;
  font-family: var(--font-body); font-size: 15px; color: var(--ink); text-decoration: none;
  padding: 11px 6px; border-radius: 12px; margin-top: 4px;
}
.pmenu__row:hover { background: var(--paper-2); }
.pmenu__row--danger { color: var(--rose); }
.pmenu__row[aria-disabled="true"] { cursor: default; }
.pmenu__coins { display: inline-flex; align-items: center; gap: 5px; color: var(--gold-deep); font-weight: 700; }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(310px, .78fr);
  gap: clamp(22px, 4vw, 42px);
  align-items: center;
  margin: 20px 0 42px;
}

.hero--story {
  grid-template-columns: minmax(300px, .72fr) minmax(0, 1fr);
}

.eyebrow {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 14px;
  border-radius: 999px;
  padding: 7px 13px;
  background: rgba(244, 185, 66, .14);
  color: var(--gold);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.14;
  margin: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(40px, 8vw, 76px);
  letter-spacing: 0;
  text-shadow: 0 2px 0 rgba(0,0,0,.18), 0 0 30px rgba(244,185,66,.25);
}

.lede {
  max-width: 710px;
  margin: 18px 0 0;
  color: #eadffb;
  font-size: clamp(17px, 2.3vw, 22px);
}

.hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.hero-note {
  max-width: 620px;
  color: #cdbfe5;
  font-size: 14px;
}

.cover-frame {
  position: relative;
  border-radius: 30px;
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.48), rgba(255,255,255,.12)),
    linear-gradient(135deg, rgba(244,185,66,.7), rgba(255,111,145,.48), rgba(63,200,180,.42));
  box-shadow: var(--shadow-lg);
}

.cover-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 22px;
}

.section-title {
  margin: 48px 0 20px;
  text-align: center;
  font-size: clamp(28px, 5vw, 44px);
}

.filters {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: -8px 0 26px;
}

.chip {
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  color: #eadffb;
  font-size: 14px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}
.chip:hover {
  border-color: rgba(255,255,255,.3);
  transform: translateY(-1px);
}
.chip.is-active {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  border-color: transparent;
  color: var(--sky-1);
  font-weight: 600;
}

.story-grid__empty {
  margin: 30px 0 0;
  text-align: center;
  color: #cdbfe5;
  font-size: 15px;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.story-card {
  overflow: hidden;
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(transparent, transparent 37px, rgba(200,170,110,.1) 38px),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: var(--shadow-md);
}

.story-card__image {
  position: relative;
  display: block;
  overflow: hidden;
}

.story-card__image img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

.story-card__tag {
  position: absolute;
  top: 14px;
  right: 14px;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(36, 18, 66, .78);
  color: var(--paper);
  font-size: 12px;
}

.story-card__body {
  padding: 20px;
}

.story-card h3 {
  font-size: 25px;
  color: var(--ink);
}

.story-card p {
  margin: 10px 0 16px;
  color: var(--ink-soft);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.meta {
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff8eb;
  border: 1px solid var(--paper-line);
  color: var(--ink-soft);
  font-size: 13px;
}

.story-layout {
  display: grid;
  grid-template-columns: minmax(250px, 360px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.sticky-panel {
  position: sticky;
  top: 22px;
}

.paper-card {
  position: relative;
  border-radius: var(--radius);
  padding: clamp(22px, 5vw, 34px);
  background:
    repeating-linear-gradient(transparent, transparent 37px, rgba(200,170,110,.13) 38px),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: var(--shadow-lg);
}

.paper-card::before {
  content: "";
  position: absolute;
  inset: 6px 6px auto 6px;
  height: 5px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--rose), var(--gold), var(--teal));
}

.paper-card h2 {
  color: var(--ink);
  font-size: clamp(27px, 5vw, 38px);
  margin-bottom: 12px;
}

.paper-card h3 {
  margin: 26px 0 8px;
  color: var(--ink);
  font-size: 23px;
}

.paper-card p,
.paper-card li {
  color: var(--ink-soft);
  font-size: 17px;
}

.paper-card p { margin: 0 0 14px; }
.paper-card ul { margin: 10px 20px 0 0; padding: 0; }

.quote {
  margin: 22px 0;
  border-inline-start: 5px solid var(--gold);
  padding: 16px 18px;
  border-radius: 18px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 19px;
}

.story-reading-card {
  overflow: hidden;
}

.reader {
  margin-top: 30px;
  padding: clamp(16px, 3vw, 28px);
  border-radius: 22px;
  background: #eee2cb;
  border: 1px solid #d8c29a;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 18px 34px -28px rgba(32, 16, 45, .8);
}

.reader__topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.reader__eyebrow,
.reader__direction {
  color: var(--ink-soft);
  font-size: 13px;
}

.reader__title {
  margin-top: 3px;
  font-size: clamp(25px, 4vw, 36px);
}

.reader__book {
  position: relative;
  min-height: 510px;
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf8;
  box-shadow: 0 18px 28px -18px rgba(31, 18, 38, .8), 0 0 0 1px rgba(96, 69, 38, .18);
  outline: none;
}

.reader__book[hidden] {
  display: none;
}

.reader__book:focus-visible {
  box-shadow: 0 0 0 4px rgba(244, 185, 66, .8), 0 18px 28px -18px rgba(31, 18, 38, .8);
}

.reader__book--cover {
  display: grid;
  place-items: center;
  width: min(100%, 560px);
  min-height: 650px;
  margin: 0 auto;
  cursor: pointer;
}

.reader__cover {
  position: absolute;
  inset: 0;
  background: #241242;
}

.reader__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reader__cover-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(16, 8, 28, .78));
}

.reader__cover h3 {
  position: absolute;
  right: 7%;
  bottom: 12%;
  left: 7%;
  color: #fffdf8;
  font-size: clamp(32px, 6vw, 60px);
  text-align: center;
  text-shadow: 0 3px 12px rgba(0,0,0,.45);
}

.reader__cover span {
  position: absolute;
  right: 0;
  bottom: 6%;
  left: 0;
  color: #ffe7a5;
  font-size: 13px;
  text-align: center;
}

.reader__book--spread {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  direction: ltr;
  min-height: 510px;
  margin-top: 18px;
  cursor: pointer;
  background: #fffdf8;
}

.reader__page {
  min-width: 0;
  min-height: 510px;
}

.reader__page--text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(24px, 5vw, 64px);
  direction: rtl;
  background:
    repeating-linear-gradient(transparent, transparent 37px, rgba(200,170,110,.12) 38px),
    #fffdf8;
  color: var(--ink);
  box-shadow: inset -18px 0 24px -24px rgba(40, 22, 22, .7);
}

.reader__page--text p {
  margin: 14px 0 0;
  color: var(--ink);
  font-size: clamp(17px, 2vw, 22px);
  line-height: 2;
}

.reader__page-number {
  color: var(--gold-deep);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

.reader__page--image {
  background: #e9e0d0;
}

.reader__page--image img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 510px;
  object-fit: cover;
}

.reader__click-hint {
  position: absolute;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(36, 18, 66, .78);
  color: #fffdf8;
  font-size: 12px;
  opacity: .86;
  pointer-events: none;
}

.reader__click-hint--cover {
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.reader__click-hint--next {
  bottom: 14px;
  left: 16px;
}

.reader__click-hint--prev {
  right: 16px;
  bottom: 14px;
}

.reader__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.reader__nav {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid #c9ae79;
  border-radius: 999px;
  background: #fffaf0;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
}

.reader__nav:disabled {
  cursor: not-allowed;
  opacity: .38;
}

.reader__counter {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-weight: 600;
}

.reader__direction {
  margin: 13px 0 0;
  text-align: center;
}

/* ============ FULLSCREEN READING MODE ============
   "פתח את הספר" takes the reader over the whole viewport — maximum screen
   use, matching the personal-story book experience. */
body.reader-lock {
  overflow: hidden;
}

.reader__close {
  display: none;
}

.reader--fullscreen {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 100dvh;
  z-index: 80;
  margin: 0;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: clamp(12px, 2vw, 24px);
  padding-bottom: calc(clamp(12px, 2vw, 24px) + env(safe-area-inset-bottom));
}

.reader--fullscreen .reader__close {
  display: grid;
  place-items: center;
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  z-index: 6;
  width: 44px;
  height: 44px;
  border: 1px solid #c9ae79;
  border-radius: 12px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
}

.reader--fullscreen .reader__topline {
  margin-bottom: 10px;
  padding-inline-start: 56px; /* clear the close button */
}

.reader--fullscreen .reader__book--cover {
  flex: 1;
  min-height: 0;
  width: min(100%, 640px);
}

.reader--fullscreen .reader__book--spread {
  flex: 1;
  min-height: 0;
  margin-top: 0;
}

.reader--fullscreen .reader__page {
  min-height: 0;
}

.reader--fullscreen .reader__page--image img {
  min-height: 0;
  height: 100%;
}

/* rotate-device hint — only inside fullscreen, only on small portrait screens */
.reader__rotate-hint {
  display: none;
  margin: 10px 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}

@media (orientation: portrait) and (max-width: 760px) {
  .reader--fullscreen .reader__rotate-hint {
    display: block;
  }

  /* narrow portrait: stack the spread — image on top, text below */
  .reader--fullscreen .reader__book--spread {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr);
  }

  .reader--fullscreen .reader__page--image {
    order: -1;
  }

  .reader--fullscreen .reader__page--text {
    overflow-y: auto;
  }
}

.page-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.story-page {
  border-radius: 20px;
  padding: 18px;
  background: #fffaf1;
  border: 1px solid var(--paper-line);
}

.story-page__image {
  display: block;
  width: min(100%, 520px);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  margin: 14px auto 18px;
  border-radius: 18px;
  box-shadow: 0 14px 30px -18px rgba(20, 8, 40, .75);
}

.hero-actions button {
  cursor: pointer;
}

.story-page strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 19px;
}

.product-box {
  display: grid;
  gap: 12px;
}

.product-box .button {
  width: 100%;
}

.footer {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,.12);
  color: #ccbce9;
  text-align: center;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.footer__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
}
.footer__link {
  color: var(--gold);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  transition: color .2s;
}
.footer__link:hover { color: var(--paper); text-decoration: underline; }

@media (max-width: 900px) {
  .hero,
  .hero--story,
  .story-layout {
    grid-template-columns: 1fr;
  }

  .story-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sticky-panel {
    position: relative;
    top: auto;
    max-width: 430px;
    margin: 0 auto;
  }

  .reader__book--cover,
  .reader__book--spread,
  .reader__page {
    min-height: 430px;
  }

  .reader__page--image img {
    min-height: 430px;
  }
}

@media (max-width: 620px) {
  .reader__topline {
    align-items: flex-start;
    flex-direction: column;
  }

  .reader__read {
    width: 100%;
  }

  .reader__book--cover,
  .reader__book--spread,
  .reader__page {
    min-height: 360px;
  }

  .reader__page--text {
    padding: 18px;
  }

  .reader__page--text p {
    font-size: 15px;
    line-height: 1.7;
  }

  .reader__page--image img {
    min-height: 360px;
  }

  .reader__click-hint {
    display: none;
  }
}

@media (max-width: 620px) {
  .page {
    width: min(100% - 22px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-header__account {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-actions {
    width: 100%;
  }

  .pill-link,
  .button {
    flex: 1 1 auto;
  }

  .story-grid {
    grid-template-columns: 1fr;
  }

  .paper-card {
    padding: 22px 18px;
  }
}

/* loading / empty / error states for the DB-driven catalog and reader */
.story-grid__state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 16px;
  font-size: 18px;
  opacity: 0.85;
}
.story-grid__state a {
  color: inherit;
  text-decoration: underline;
}
