/* ── Stories view (root-level /stories) ─────────────────────────────────────
   ABDL written fiction with a built-in paginated reader, rendered inside the
   main app (reuses login, likes, and the account modal). Deliberately mirrors
   tracks.css so the three sections read as one product — same dark surface,
   same top bar geometry, same card grid. Unlike Tracks, stories have real
   cover images, so the grid is cover-driven rather than generated art.

   Phase 0: shell + top bar + empty state only. The cover grid, series overview
   and reader chrome land in later phases. */

/* View switching: when the stories view is active, hide the gallery topbar + grid
   (mirrors tracks.css's view-tracks handling). */
#storiesView { display: none; }
body.view-stories #storiesView { display: block; }
body.view-stories .topbar,
body.view-stories #grid { display: none !important; }

.storiesView {
  min-height: 100vh;
  background:
    radial-gradient(90% 60% at 50% -10%, rgba(94, 231, 247, 0.10) 0%, rgba(11, 13, 18, 0) 60%),
    radial-gradient(80% 50% at 100% 0%, rgba(247, 110, 178, 0.10) 0%, rgba(11, 13, 18, 0) 55%),
    #0b0d12;
  color: #e8e9ee;
}

/* ── Top bar (home left · logo center · account right) ─────────────────────────
   Same geometry as .tracksbar / .topbar so the bar height and button-to-edge
   spacing are identical across sections. */
.storiesbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(11, 13, 18, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

@media (max-width: 520px), (pointer: coarse) {
  .storiesbar { padding: 4px 8px; }
}

.storiesbar__left,
.storiesbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.storiesbar__left { justify-self: start; }
.storiesbar__right { justify-self: end; }

/* Home + account buttons reuse the Gallery's circular .uBtn.filterBtn from style.css;
   only the authed-account glow needs a stories-scoped rule. */
#storiesAccountBtn.accountBtn--authed .filterIcon {
  stroke: #5ee7f7;
  filter: drop-shadow(0 0 6px rgba(94, 231, 247, 0.5));
}

.storiesbar__logo { height: 34px; width: auto; display: block; justify-self: center; }

/* ── Page shell — full width like the Gallery (no centered max-width spacers) ──── */
.stories__inner {
  padding: 16px 16px 120px;
}
@media (max-width: 600px) {
  .stories__inner { padding: 12px 12px 120px; }
}

/* ── Cover grid ───────────────────────────────────────────────────────────────
   Covers are portrait (book-shaped), so the columns are narrower than the Tracks
   grid's square art but use the same gaps and responsive behaviour. */
.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

@media (max-width: 600px) {
  .stories-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }
}

/* ── Story card ───────────────────────────────────────────────────────────────
   Same shell as .tracks-card (radius, border, hover lift, focus ring, stagger-in)
   so the grids feel identical; only the art area differs — portrait cover instead
   of square generated art. */
.stories-card {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  animation: storiesCardIn 260ms ease backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
}
@media (hover: hover) and (pointer: fine) {
  .stories-card:hover {
    transform: translateY(-3px);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(94, 231, 247, 0.35);
  }
}
.stories-card:focus-visible {
  outline: 2px solid rgba(94, 231, 247, 0.8);
  outline-offset: 2px;
}

@keyframes storiesCardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .stories-card { animation: none; }
}

/* Cover area — book-shaped (2:3). Holds either the uploaded image or the
   generated placeholder; both fill the same box so the grid stays even. */
.stories-card__cover {
  position: relative;
  aspect-ratio: 2 / 3;
  background: linear-gradient(150deg, var(--g1, #5ee7f7), var(--g2, #f76eb2));
  overflow: hidden;
}
.stories-card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Generated placeholder: the title set over the story's own gradient, so a
   coverless story still reads as a distinct book rather than a blank tile. */
.stories-card__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.22;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.96);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  /* Darkened scrim so long titles stay legible over the lighter gradient stops. */
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.10) 0%, rgba(0, 0, 0, 0.42) 100%);
  overflow: hidden;
}

/* SERIES badge — same pill as .tracks-card__badge. */
.stories-card__badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #06232b;
  background: #5ee7f7;
  padding: 2px 8px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* ── Like heart ───────────────────────────────────────────────────────────────
   Used on story cards, part cards, the overview head and the reader bar. On cards
   it sits bottom-right of the cover and appears on hover (always visible on touch,
   where there is no hover), mirroring the gallery's .like-btn behaviour. */
.stories-like {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 3;
  width: 34px;
  height: 34px;
  padding: 7px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
}
.stories-card:hover .stories-like,
.stories-like:focus-visible { opacity: 1; transform: scale(1); }
.stories-like:hover { background: rgba(0, 0, 0, 0.8); }
.stories-like:focus-visible { outline: 2px solid rgba(94, 231, 247, 0.8); outline-offset: 2px; }
.stories-like svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.stories-like.is-liked { color: #ec4899; opacity: 1; transform: scale(1); }
.stories-like.is-liked svg { fill: currentColor; stroke: none; }

/* No hover on touch — keep hearts visible so they're reachable. */
@media (hover: none) {
  .stories-like { opacity: 1; transform: scale(1); background: rgba(0, 0, 0, 0.35); }
}

/* Guests can't like; hide the hearts entirely rather than showing a dead control. */
body.guest .stories-like { display: none !important; }

/* Overview head + reader bar: inline rather than pinned to a cover. */
.stories-like--head {
  position: static;
  opacity: 1;
  transform: none;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
.stories-like--head:hover { background: rgba(255, 255, 255, 0.12); }
.stories-like--bar {
  position: static;
  opacity: 1;
  transform: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
.stories-like--bar:hover { background: rgba(255, 255, 255, 0.12); }

.stories-card__body { padding: 11px 13px 14px; }
.stories-card__title {
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
  color: #f3f4f8;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.stories-card__meta {
  margin-top: 4px;
  font-size: 0.82rem;
  color: rgba(232, 233, 238, 0.6);
}

/* ── Loading skeleton (mirrors the Tracks grid's loading state) ─────────────── */
.stories-skel {
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.stories-skel__cover {
  aspect-ratio: 2 / 3;
  background: linear-gradient(100deg, rgba(255,255,255,0.05) 30%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.05) 70%);
  background-size: 200% 100%;
  animation: storiesShimmer 1.3s linear infinite;
}
.stories-skel__body { padding: 12px 13px 16px; }
.stories-skel__line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(100deg, rgba(255,255,255,0.05) 30%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.05) 70%);
  background-size: 200% 100%;
  animation: storiesShimmer 1.3s linear infinite;
}
.stories-skel__line + .stories-skel__line { margin-top: 10px; }
.stories-skel__line--title { width: 78%; height: 15px; }
.stories-skel__line--meta { width: 42%; }

@keyframes storiesShimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .stories-skel__cover, .stories-skel__line { animation: none; }
}

/* ── Series overview (/stories/<slug>) ────────────────────────────────────────
   Cover + title + ordered part list. The user picks a part; nothing auto-opens
   (design doc §6 — reading is self-paced, unlike the Tracks playlist). */
.stories__inner--detail { max-width: 900px; margin: 0 auto; }

.stories-detail__loading { padding: 60px 0; text-align: center; color: rgba(232, 233, 238, 0.6); }

.stories-detail__back {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  color: rgba(232, 233, 238, 0.78);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.stories-detail__back:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.stories-detail__back:focus-visible { outline: 2px solid rgba(94, 231, 247, 0.8); outline-offset: 2px; }

.stories-detail__head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
/* No cover here — a story's cover is its first part's, which already appears as the first card
   in the grid below, so repeating it in the head was pure duplication. */
.stories-detail__meta { min-width: 0; flex: 1 1 auto; }
.stories-detail__title {
  margin: 0;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.stories-detail__submeta { margin: 6px 0 0; font-size: 0.85rem; color: rgba(232, 233, 238, 0.55); }

/* Part cards on a series overview use the shared .stories-card shell (see above) — each part is
   its own book. Only the order badge and the progress bar are specific to them. */
.stories-card__badge--order {
  left: auto;
  right: 8px;
  min-width: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.stories-card[disabled] { opacity: 0.55; cursor: default; }
.stories-card[disabled]:hover { transform: none; box-shadow: none; background: rgba(255, 255, 255, 0.05); }

/* Reading progress on a card (logged-in readers only). */
.stories-card__bar {
  display: block;
  margin-top: 8px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}
.stories-card__barfill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5ee7f7, #f76eb2);
}

/* ── Reader (design doc §4) ───────────────────────────────────────────────────
   Fixed pages, one per swipe, scaled to fit with letterboxing. No appearance
   controls by design — one consistent presentation for everyone. Fills the
   viewport so the page gets as much room as possible. */
.stories-reader {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: #0b0d12;
}

.reader-bar {
  flex: 0 0 auto;
  display: grid;
  /* back · title · like  (the ✕ was removed — it duplicated the back arrow) */
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(11, 13, 18, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.reader-bar__title {
  min-width: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: #e8e9ee;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-bar__sub {
  display: block;
  font-size: 0.74rem;
  font-weight: 500;
  color: rgba(232, 233, 238, 0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Stage — the page (auto-cropped to its content) sits centred here, scaled to fit. */
.reader-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 10px;
  touch-action: pan-y;
}
.reader-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 8px 34px rgba(0, 0, 0, 0.6);
}
.reader-stage__msg {
  color: rgba(232, 233, 238, 0.6);
  font-size: 0.9rem;
  text-align: center;
  padding: 0 20px;
  max-width: 30rem;
}

/* Page-turn buttons — always visible so the reader works without knowing the
   swipe gesture (design doc §4). */
.reader-nav {
  all: unset;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #e8e9ee;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, opacity 0.15s ease;
}
.reader-nav:hover { background: rgba(0, 0, 0, 0.75); }
.reader-nav:focus-visible { outline: 2px solid rgba(94, 231, 247, 0.8); outline-offset: 2px; }
.reader-nav[disabled] { opacity: 0.25; pointer-events: none; }
.reader-nav--prev { left: 10px; }
.reader-nav--next { right: 10px; }
.reader-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* Touch devices swipe, so the arrows are dead weight over the page — hide them and give the
   story the full stage. They stay on pointer devices, where there's no swipe affordance. */
@media (pointer: coarse) {
  .reader-nav { display: none; }
}

/* Progress — "Page X of Y" plus a thin gradient fill. */
.reader-foot {
  flex: 0 0 auto;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(11, 13, 18, 0.82);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.reader-progress {
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
  margin-bottom: 6px;
}
.reader-progress__fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #5ee7f7, #f76eb2);
  transition: width 0.2s ease;
}
.reader-count {
  text-align: center;
  font-size: 0.8rem;
  color: rgba(232, 233, 238, 0.65);
  font-variant-numeric: tabular-nums;
}

/* ── Empty / error state (matches .tracks-empty) ───────────────────────────── */
.stories-empty {
  grid-column: 1 / -1;
  padding: 48px 16px;
  text-align: center;
  color: rgba(232, 233, 238, 0.6);
  font-size: 14.5px;
}
