/* ==========================================================================
   Memmy World — story sheet
   --------------------------------------------------------------------------
   The card grid is the shelf; this is the book you take off it. A warm paper
   panel over the deepest tint in the page, so reading a story always feels
   like stepping out of the film for a moment.
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vh, 40px) var(--shell);
}

.modal[hidden] {
  display: none;
}

.modal__scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(7, 5, 11, 0.72), rgba(7, 5, 11, 0.94));
  backdrop-filter: blur(7px) saturate(0.9);
  animation: modal-fade 0.28s var(--ease-out) both;
}

.modal__panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  /* One definite row: without it the row is `auto`, so a long story grew the
     panel past its own max-height and `overflow: hidden` clipped the action bar
     off the bottom of the screen. `minmax(0, 1fr)` lets the body shrink and
     scroll instead. */
  grid-template-rows: minmax(0, 1fr);
  width: min(1040px, 100%);
  height: min(760px, 100%);
  max-height: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--paper);
  color: var(--paper-ink);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 50px 120px -40px rgba(0, 0, 0, 0.95),
    0 0 0 1px var(--accent-line),
    0 0 90px -30px var(--accent-glow);
  animation: modal-rise 0.34s var(--ease-out) both;
}

@keyframes modal-fade {
  from { opacity: 0; }
}

@keyframes modal-rise {
  from {
    opacity: 0;
    transform: translate3d(0, 24px, 0) scale(0.985);
  }
}

/* -------------------------------- media -------------------------------- */
.modal__media {
  position: relative;
  min-height: clamp(180px, 34vh, 420px);
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  overflow: hidden;
  isolation: isolate;
}

.modal__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 40%;
}

.modal__media-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(9, 6, 14, 0.62), transparent 46%),
    radial-gradient(80% 60% at 50% 108%, var(--aura), transparent 62%);
  mix-blend-mode: screen;
  opacity: 0.5;
}

/* -------------------------------- close -------------------------------- */
.modal__close {
  position: absolute;
  z-index: 3;
  top: 12px;
  inset-inline-end: 12px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(36, 26, 13, 0.12);
  background: rgba(255, 250, 241, 0.88);
  color: var(--paper-ink);
  backdrop-filter: blur(8px);
  transition: background 0.2s, transform 0.2s var(--ease-out), color 0.2s;
}

.modal__close svg {
  width: 16px;
  height: 16px;
}

.modal__close:hover {
  background: var(--accent);
  color: #1a1206;
  transform: rotate(90deg);
}

/* --------------------------------- body -------------------------------- */
.modal__body {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.6vh, 16px);
  padding: clamp(18px, 3vw, 34px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(to bottom, var(--paper), #fff4e2);
  /* Without this a grid item refuses to shrink below its content, so the panel
     grew past its own max-height and `overflow: hidden` clipped the action bar
     off the bottom of the sheet. */
  min-height: 0;
}

.modal__kicker {
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal__title {
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  letter-spacing: -0.02em;
  text-wrap: balance;
  color: var(--paper-ink);
}

.modal__lede {
  color: var(--paper-ink-soft);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
/* ------------------------------- blocks -------------------------------- */
.modal__block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal__block h3 {
  color: var(--accent);
  font-family: var(--body);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal__block p {
  color: var(--paper-ink-soft);
  font-size: 0.86rem;
  line-height: 1.62;
  white-space: pre-line;
}

/* ------------------------------- actions ------------------------------- */
/* The action bar sticks to the bottom of the body and stays reachable. */
.modal__actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: auto;
  margin-inline: calc(-1 * clamp(18px, 3vw, 34px));
  padding: clamp(10px, 1.6vh, 16px) clamp(18px, 3vw, 34px);
  border-top: 1px solid rgba(36, 26, 13, 0.1);
  background: #fff4e2;
  box-shadow: 0 -18px 26px -18px rgba(36, 26, 13, 0.45);
}

.modal__actions .btn {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--paper-ink);
  border-color: rgba(36, 26, 13, 0.18);
  background: rgba(36, 26, 13, 0.06);
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal__actions .btn--solid {
  color: #1a1206;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.modal__actions .btn--ghost:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* `[hidden]` is only `display: none` in the UA stylesheet, so any author rule
   that sets `display` on the element wins and the attribute does nothing. `.btn`
   is `inline-flex`, which is why a story with no colouring page still painted
   this button — carrying world.html's static French fallback label and no href,
   so Arabic readers were shown a dead "Page à colorier". Scoped and weighted
   (class + class + attribute) so it beats `.modal__actions .btn` without
   `!important`. */
.modal__actions .btn[hidden] {
  display: none;
}

/* ----------------------------- narrow view ----------------------------- */
@media (max-width: 780px) {
  .modal {
    padding: 0;
    place-items: end stretch;
  }

  .modal__panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: auto;
    max-height: 94svh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: modal-sheet 0.32s var(--ease-out) both;
  }

  @keyframes modal-sheet {
    from {
      opacity: 0;
      transform: translate3d(0, 40px, 0);
    }
  }

  .modal__media {
    min-height: clamp(120px, 24vh, 200px);
  }

  .modal__body {
    padding: 16px var(--shell) max(18px, env(safe-area-inset-bottom));
  }

  .modal__actions .btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal__scrim,
  .modal__panel {
    animation: none;
  }

  .modal__close:hover {
    transform: none;
  }
}

/* ==========================================================================
   The story preview modal — missing utility rules
   --------------------------------------------------------------------------
   `.modal__notice` and `.modal__buy` are rendered by story-modal.js and
   purchase.js respectively; both need to fit inside `.modal__body`. */

/* A short "content locked until payment" notice above the buy button. */
.modal__notice {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--paper-ink-soft);
  letter-spacing: 0.01em;
}

/* The primary buy CTA in the preview sheet. It is a `.btn.btn--solid`
   descendant of `.modal__actions`, so the existing rules already paint it
   correctly; this rule only gives it a minimum width so the lock icon and
   the price label are never clipped on narrow cards. */
.modal__buy {
  flex: 1 1 auto;
  min-width: min(220px, 100%);
}

/* ==========================================================================
   Purchase entry-point sheet (#buy-sheet)
   --------------------------------------------------------------------------
   Opens from every buy affordance on the page (cards, preview modal, QR).
   Styled as a bottom-sheet on phones and as a narrow side-panel on wider
   screens so it never covers the whole film the way a full modal would.
   ========================================================================== */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center end;
  pointer-events: none;
}

.sheet[hidden] {
  display: none;
}

/* Scrim: lighter than the story modal's so the film is still readable behind. */
.sheet__scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(7, 5, 11, 0.6), rgba(7, 5, 11, 0.86));
  backdrop-filter: blur(5px) saturate(0.9);
  pointer-events: auto;
  animation: sheet-fade 0.26s var(--ease-out) both;
}

/* The panel itself: a warm paper column, full viewport height on desktop. */
.sheet__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(430px, 100vw);
  height: 100%;
  max-height: 100svh;
  background: var(--paper);
  color: var(--paper-ink);
  border-inline-start: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    -40px 0 100px -40px rgba(0, 0, 0, 0.9),
    0 0 0 1px var(--accent-line) inset;
  pointer-events: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: sheet-rise 0.32s var(--ease-out) both;
}

@keyframes sheet-fade {
  from { opacity: 0; }
}

@keyframes sheet-rise {
  from {
    opacity: 0;
    transform: translate3d(40px, 0, 0);
  }
}

/* Close button — shared style with `.modal__close`. */
.sheet__panel .modal__close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
}

/* Cover image: fills the top of the panel. */
.sheet__media {
  flex: 0 0 auto;
  position: relative;
  min-height: clamp(140px, 28vh, 240px);
  background: linear-gradient(150deg, var(--accent-soft), rgba(9, 6, 14, 0.5));
  overflow: hidden;
}

.sheet__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 40%;
}

/* Warm gradient over the cover so the kicker text stays legible. */
.sheet__media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(255, 250, 241, 0.72) 0%, transparent 55%);
}

/* Scrollable body. */
.sheet__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
  padding: clamp(18px, 3vw, 28px);
  background: linear-gradient(to bottom, var(--paper), #fff4e2);
  min-height: 0;
}

.sheet__kicker {
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.sheet__title {
  font-family: var(--display);
  font-size: clamp(1.25rem, 2.4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-wrap: balance;
  color: var(--paper-ink);
}

.sheet__price {
  font-family: var(--display);
  font-size: clamp(1.3rem, 2vw, 1.65rem);
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.01em;
}

.sheet__sub {
  color: var(--paper-ink-soft);
  font-size: 0.84rem;
  line-height: 1.6;
}

.sheet__notice {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--paper-ink-soft);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
}

/* "Payment coming soon" block: gives an honest status without blocking the UI. */
.sheet__soon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(36, 26, 13, 0.14);
  background: rgba(36, 26, 13, 0.04);
}

.sheet__soon h3 {
  font-family: var(--body);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-ink);
}

.sheet__soon p {
  color: var(--paper-ink-soft);
  font-size: 0.78rem;
  line-height: 1.55;
}

/* Copy-link row + the URL it displays. */
.sheet__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: clamp(10px, 1.6vh, 16px);
  border-top: 1px solid rgba(36, 26, 13, 0.1);
}

.sheet__actions .btn {
  align-self: flex-start;
}

.sheet__link {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
  color: var(--paper-ink-soft);
  font-size: 0.62rem;
  line-height: 1.4;
  opacity: 0.75;
}

[dir='rtl'] .sheet__link {
  text-align: end;
}

/* ---- Narrow / phone ---- */
/* On a phone the panel slides up from the bottom instead of in from the side,
   because the full-height side column is too cramped at <500px wide. */
@media (max-width: 600px) {
  .sheet {
    place-items: end center;
  }

  .sheet__panel {
    width: 100%;
    height: auto;
    max-height: 92svh;
    border-inline-start: none;
    border-top: 1px solid var(--accent-line);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: sheet-up 0.32s var(--ease-out) both;
  }

  @keyframes sheet-up {
    from {
      opacity: 0;
      transform: translate3d(0, 40px, 0);
    }
  }

  .sheet__body {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet__scrim,
  .sheet__panel {
    animation: none;
  }
}
