/*
 * The visual-novel reader pages (visual-novel-design.md §6.6, S9): a VN book's home (templates/serial/vn-book.html)
 * and its play page (templates/serial/vn-play.html). On top of serial.css; only these two pages link it, so a
 * novel or manga page stays byte-identical. Every side is logical (inline-start / inline-end): the ar tree mirrors.
 */

/* ── book home ─────────────────────────────────────────────────────────────────────────── */
.sr-vn-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.75rem; }
.sr-vn-title-row h1 { margin: 0; }
.sr-vn-synopsis { max-width: 40rem; }
.sr-vn-actions .sr-btn svg { width: 1rem; height: 1rem; flex: none; }
.sr-vn-start svg { fill: currentColor; stroke: none; }
.sr-vn-continue[hidden], .sr-vn-fullscreen[hidden] { display: none; }
.sr-vn-continue-where { font-weight: 400; font-size: 0.875rem; color: var(--sr-muted-foreground);
  max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }

.sr-vn-columns { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2rem; margin: 2.25rem 0 0; }
@media (min-width: 1024px) { .sr-vn-columns { grid-template-columns: minmax(0, 1fr) 300px; gap: 2.5rem; } }
.sr-vn-toc .sr-list a { align-items: center; }
.sr-vn-thumb { flex: none; width: 4.5rem; aspect-ratio: 16 / 9; border-radius: 0.25rem; background: var(--sr-muted);
  background-size: cover; background-position: center; }
.sr-vn-scenes { flex: none; font-size: 0.8125rem; color: var(--sr-muted-foreground); }
.sr-vn-aside { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.sr-vn-aside .sr-heading { margin-bottom: 0.6rem; }
.sr-vn-cast-list { display: flex; flex-wrap: wrap; gap: 0.6rem 1.25rem; margin: 0; padding: 0; list-style: none; }
.sr-vn-cast-list li { display: inline-flex; align-items: center; gap: 0.5rem; }
.sr-vn-avatar { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem;
  border-radius: 999px; background: var(--sr-secondary); color: var(--sr-secondary-foreground); font-size: 0.875rem;
  background-size: cover; background-position: center; overflow: hidden; }
.sr-vn-avatar.has-picture { color: transparent; }
.sr-vn-endings p { margin: 0; }
.sr-vn-ad { align-self: center; }
/* Phone (the approved Book-m mockup): the cover sits beside the title, the 視覺小說 tag and the author / stats only;
   the synopsis and the buttons take the full width under it. The body's box is dissolved (display: contents) so
   its children land in the head's grid; the meta row takes the rows the cover is taller by. The world link is the
   breadcrumb's second step already, so the phone leaves it out of the meta line. */
@media (max-width: 639px) {
  .sr-vn-head { grid-template-columns: 6.5rem minmax(0, 1fr); grid-template-rows: auto 1fr auto auto;
    grid-template-areas: "cover title" "cover meta" "synopsis synopsis" "actions actions"; row-gap: 0; }
  .sr-vn-head .sr-book-hero-cover { grid-area: cover; }
  .sr-vn-head .sr-book-head-body { display: contents; }
  .sr-vn-head .sr-vn-title-row { grid-area: title; flex-direction: column; align-items: flex-start; }
  .sr-vn-head .sr-world-meta { grid-area: meta; align-self: start; margin: 0.4rem 0 0; }
  .sr-vn-head .sr-world-meta > a { display: none; }
  .sr-vn-head .sr-vn-synopsis { grid-area: synopsis; margin-top: 1rem; }
  .sr-vn-head .sr-vn-actions { grid-area: actions; }
  /* 繼續 names its chapter and scene in full: one line when it fits, two when it does not — never an ellipsis. */
  .sr-vn-actions .sr-vn-continue { flex-wrap: wrap; white-space: normal; text-align: center; row-gap: 0.15rem; }
  .sr-vn-actions .sr-vn-continue-where { max-width: none; overflow: visible; }
  .sr-vn-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .sr-vn-actions .sr-vn-start, .sr-vn-actions .sr-vn-continue { grid-column: 1 / -1; }
  .sr-vn-actions .sr-follow-slot, .sr-vn-actions .sr-share { min-width: 0; }
  .sr-vn-actions .sr-follow-slot .sr-btn, .sr-vn-actions .sr-share .sr-share-btn { width: 100%; justify-content: center; }
  .sr-vn-actions .sr-follow-slot { display: flex; }
  /* The author's own book has no 追蹤 (the follow script hides the button): 分享 then takes the whole row instead of
     half of it. */
  .sr-vn-actions .sr-follow-slot:not(:has(.sr-follow:not([hidden]))) { display: none; }
  .sr-vn-actions .sr-follow-slot:not(:has(.sr-follow:not([hidden]))) + .sr-share { grid-column: 1 / -1; }
}

/* ── play page ─────────────────────────────────────────────────────────────────────────── */
.sr-vn-play { padding-bottom: 3rem; }
.sr-vn-play-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1rem 0 0.75rem; }
.sr-vn-play-bar .sr-crumbs { margin: 0; min-width: 0; }
.sr-vn-fullscreen { flex: none; }
.sr-vn-fullscreen svg { width: 1rem; height: 1rem; }
/* The 16:9 stage: as wide as the column, never taller than the window under the top bar. */
.sr-vn-stage-wrap { position: relative; margin: 0 auto;
  width: min(100%, calc((100dvh - 9rem) * 16 / 9)); }
.sr-vn-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #0f0d0a; border-radius: 0.375rem;
  overflow: hidden; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18); }
.sr-vn-stage > .vnp-island-host { position: absolute; inset: 0; }
.sr-vn-back { display: none; }
.sr-vn-stage-wrap:fullscreen { width: 100%; height: 100%; background: #000; display: flex; align-items: center; }
.sr-vn-stage-wrap:fullscreen .sr-vn-stage { height: 100%; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
.sr-vn-chapter-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 1.25rem 0 0; padding-bottom: 1.25rem; border-bottom: 1px solid var(--sr-border); }
.sr-vn-chapter-title { margin: 0; font-size: 1.5rem; line-height: 1.35; }
.sr-vn-chapter-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; margin: 0.25rem 0 0; }
.sr-vn-chapter-actions { margin: 0; }
.sr-vn-sheet-head { display: none; }
.sr-vn-comments .sr-comments { margin-top: 1.5rem; padding-top: 0; border-top: 0; }

/* Phone (upright, or on its side with little height): the stage IS the screen (§6.6). The page under it — the
   chapter's title, follow, share — stays in the document for the island to read; the comments open as a sheet. */
@media (max-width: 767px), (max-height: 500px) {
  html.sr-vn-play-page, html.sr-vn-play-page body { overflow: hidden; height: 100%; }
  .sr-vn-play-bar, .sr-vn-chapter-info { display: none; }
  .sr-vn-stage-wrap { position: fixed; inset: 0; z-index: 60; width: 100%; height: 100dvh; margin: 0; background: #0f0d0a; }
  .sr-vn-stage { height: 100%; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
  .sr-vn-back { position: absolute; z-index: 5; inset-block-start: 0.75rem; inset-inline-start: 0.75rem;
    display: inline-flex; align-items: center; gap: 0.5rem; min-height: 2.75rem; padding-block: 0; padding-inline: 0.5rem 0.75rem;
    border-radius: 999px; color: #faf8f5; background: rgba(15, 13, 10, 0.45); text-decoration: none;
    font-size: 0.875rem; max-width: calc(100% - 1.5rem); }
  .sr-vn-back svg { width: 1.25rem; height: 1.25rem; flex: none; }
  .sr-vn-back-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* The player's title screen and menus have their own exits: the arrow stays out of their way. */
  .sr-vn-stage-wrap:has(.vnp[data-phase="title"]) .sr-vn-back-title { display: none; }
  .sr-vn-comments { position: fixed; z-index: 70; inset-inline: 0; inset-block-end: 0; height: 76dvh;
    display: flex; flex-direction: column; background: var(--sr-background); color: var(--sr-foreground);
    border-start-start-radius: 1rem; border-start-end-radius: 1rem; box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.3);
    transform: translateY(105%); transition: transform 0.25s ease; visibility: hidden; }
  .sr-vn-comments.is-open { transform: none; visibility: visible; }
  .sr-vn-sheet-head { position: relative; display: flex; justify-content: center; align-items: center; min-height: 2.75rem; flex: none; }
  .sr-vn-sheet-grip { width: 2.5rem; height: 0.25rem; border-radius: 999px; background: var(--sr-border); }
  .sr-vn-sheet-close { position: absolute; inset-inline-end: 1rem; inset-block-start: 0.25rem; display: inline-flex;
    align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; border: 0; background: none;
    color: inherit; cursor: pointer; }
  .sr-vn-sheet-close svg { width: 1.25rem; height: 1.25rem; }
  .sr-vn-comments .sr-comments { margin: 0; padding: 0 1rem 1.25rem; overflow-y: auto; min-height: 0; }
  .sr-vn-play .sr-report-row { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sr-vn-comments { transition: none; } }
