/* ============================================================
   Smart Write — Reader preview
   ============================================================ */

.shell--reader #menu-editor-content {
  display: none !important;
}

.shell--reader #view-editor-host {
  display: none !important;
}

.shell--reader .details-panel {
  display: none !important;
}

.shell--reader .app-stage {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.shell--reader .app-stage > .view-host {
  flex: 1;
  min-height: 0;
}

.shell--reader .reader-stage {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  align-items: stretch;
  justify-content: center;
  position: relative;
  background: var(--app-bg);
  overflow: hidden;
}

.reader-stage__viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 24px 56px 40px;
  scroll-snap-type: y mandatory;

}

.reader-stage__loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--app-bg-base) 88%, transparent);
}

.reader-stage__loading[hidden] {
  display: none !important;
}

.reader-spinner,
.analysis-chat__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--hairline);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: reader-spin 0.85s linear infinite;
}

@keyframes reader-spin {
  to { transform: rotate(360deg); }
}

.reader-stage__loading-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.reader-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 72px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
  opacity: 0.85;
}

.shell--reader .reader-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
}

.reader-nav:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
}

.reader-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.shell--reader .reader-nav--prev {
  left: 8px;
}

.shell--reader .reader-nav--next {
  right: 8px;
}

/* Scroll mode — up/down controls stacked on the right */
.shell--reader .reader-stage--scroll .reader-nav {
  transform: none;
}

.shell--reader .reader-stage--scroll .reader-nav--prev {
  left: auto;
  right: 8px;
  top: calc(50% - 76px);
}

.shell--reader .reader-stage--scroll .reader-nav--next {
  top: calc(50% + 4px);
}

.shell--reader .reader-stage--scroll .reader-nav--prev .ico {
  transform: rotate(90deg);
}

.shell--reader .reader-stage--scroll .reader-nav--next .ico {
  transform: rotate(90deg);
}


/* TOC panel */
.reader-toc-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.reader-toc-panel .sidebar-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.reader-page-controls {
  flex-shrink: 0;
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--hairline);
}

.reader-page-controls__bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.reader-page-controls__btn {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.reader-page-controls__btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.reader-page-controls__btn--icon .ico {
  display: block;
  flex-shrink: 0;
}

.reader-page-controls__btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.reader-page-controls__btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.reader-page-controls__page {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 4px;
}

.reader-page-controls__input {
  width: 3.2rem;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--app-bg);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.reader-page-controls__input:focus {
  outline: none;
  border-color: var(--accent);
}

.reader-page-controls__total {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reader-toc-panel .reader-toc {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.reader-toc__list {
  list-style: none;
  margin: 0;
  padding: 6px 0 12px;
}

.reader-toc__item {
  margin: 0;
  overflow: visible;
}

.reader-toc__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  border-radius: 0;
}

.reader-toc__link:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.reader-toc__link.active {
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-soft);
}

.reader-toc__link--front {
  font-weight: 500;
  color: var(--text);
}

.reader-toc__bookmark {
  width: var(--bookmark-toc-width);
  height: auto;
  flex-shrink: 0;
  transform: rotate(90deg);
  transform-origin: center;
  pointer-events: auto;
  position: absolute;
  right: 20px;
}

.reader-toc__bookmark.bookmark-art {
  filter: url("#bookmark-recolor") drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.35));
}

#abgrp-reader-bookmark-actions {
  overflow: visible;
  z-index: 3;
}

#abgrp-reader-bookmark-actions:not(.is-placed) .editor-font-button-hover-pullout-content {
  display: none;
}

#abgrp-reader-bookmark-actions .editor-font-button-hover-pullout-content button {
  white-space: nowrap;
  padding: 0 10px;
  font: inherit;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}

#abgrp-reader-bookmark-actions .editor-font-button-hover-pullout-content button + button {
  border-left: 1px solid var(--hairline);
}

/* Hidden measurer (off-screen layout) */
.reader-measurer {
  position: absolute;
  left: -99999px;
  top: 0;
  width: 576px;
  height: 864px;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}

.reader-measurer__inner {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 54px 50px 72px;
  overflow: hidden;
  font-family: var(--reader-font-family, "Literata", Georgia, serif);
  font-size: 11pt;
  line-height: 1.55;
  color: #1a1a1a;
}

/* Paginated sheets in viewport */
.reader-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  margin: 0 auto;
}

.reader-sheet-slot {
  position: relative;
  width: calc(var(--reader-page-width) * var(--reader-display-scale));
  height: calc(var(--reader-page-height) * var(--reader-display-scale));
  margin: 0 auto;
  overflow: hidden;
  flex-shrink: 0;
  scroll-snap-align: center;
}

.reader-sheet-slot > .reader-sheet {
  position: absolute;
  top: 0;
  left: 0;
  transform: scale(var(--reader-display-scale));
  transform-origin: top left;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
}

.reader-sheet {
  position: relative;
  width: var(--reader-page-width, 576px);
  height: var(--reader-page-height, 864px);
  min-height: 0;
  max-height: var(--reader-page-height, 864px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #1a1a1a;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  border-radius: 2px;
  scroll-snap-align: center;
  overflow: hidden;
}

.theme-light .reader-sheet {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.reader-sheet__body {
  flex: 1 1 0;
  min-height: 0;
  box-sizing: border-box;
  padding: 54px 50px 24px;
  font-family: var(--reader-font-family, "Literata", Georgia, serif);
  font-size: 11pt;
  line-height: 1.55;
  overflow: hidden;
}

.reader-sheet__footer {
  flex-shrink: 0;
  padding: 0 50px 28px;
  text-align: center;
  font-size: 9pt;
  color: #666;
  font-variant-numeric: tabular-nums;
}

.reader-page__flow {
  width: 100%;
}

/* Typography inside sheets */
.reader-front {
  text-align: center;
}

/* Thumbnail cover art (not the full-bleed page-1 sheet) */
.reader-front .reader-cover {
  max-width: 3.2in;
  margin: 0 auto 1.2rem;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

/* Full-bleed page-1 cover — must fill the sheet, never jacket proportions */
.reader-cover--fill {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  aspect-ratio: unset;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.reader-cover__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reader-cover__generated {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--cv-bg);
  color: var(--cv-fg);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12% 10%;
  box-sizing: border-box;
}

.reader-cover__motif {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.9;
}

.reader-cover__type {
  position: relative;
  z-index: 1;
  text-align: center;
}

.reader-cover__series {
  font-size: 0.45rem;
  letter-spacing: 0.22em;
  opacity: 0.75;
  margin-bottom: 0.5rem;
}

.reader-cover__rule {
  width: 28%;
  height: 1px;
  background: currentColor;
  opacity: 0.35;
  margin: 0.4rem auto;
}

.reader-cover__title {
  font-family: "Literata", Georgia, serif;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.15;
}

.reader-cover__author {
  margin-top: 0.6rem;
  font-size: 0.55rem;
  font-style: italic;
  opacity: 0.85;
}

.reader-cover__booknum {
  margin-top: 0.5rem;
  font-size: 0.42rem;
  letter-spacing: 0.2em;
  opacity: 0.55;
}

.reader-front__title {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  line-height: 1.2;
}

.reader-front__author {
  font-size: 1rem;
  font-style: italic;
  margin: 0 0 0.75rem;
  opacity: 0.85;
}

.reader-front__meta {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.65;
  margin: 0 0 1rem;
}

.reader-front__synopsis {
  font-size: 0.95rem;
  line-height: 1.5;
  text-align: left;
  max-width: 4.5in;
  margin: 0 auto;
  opacity: 0.9;
}

.reader-body {
  text-align: justify;
}

.reader-chapter {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 1rem;
  text-align: left;
}

.reader-subhead {
  font-size: 1.1rem;
  margin: 1.2rem 0 0.6rem;
}

.reader-body p {
  margin: 0 0 0.75rem;
  text-indent: 1.5em;
}

.reader-body p:first-of-type,
.reader-chapter + p {
  text-indent: 0;
}

.reader-media {
  text-indent: 0;
  text-align: left;
}

.reader-media.media-embed--render {
  display: block;
}

.reader-page__flow:has(> .reader-media--own-page) {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.reader-media--own-page {
  max-width: 100%;
}

.reader-media--unavailable .reader-media__media,
.reader-media--unavailable .media-embed__media,
.reader-media--unavailable .media-embed__card {
  display: none;
}

.reader-media--unavailable .reader-media__fallback {
  display: block;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 12px;
  color: #666;
}

/* Header view toggle (Scroll | Pages) */
.reader-view-toggle {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  overflow: hidden;
  gap: 0;
}

.reader-view-toggle button {
  border: none;
  border-radius: 0;
  background: transparent;
  min-width: 0;
  padding: 7px 12px;
}

.reader-view-toggle button + button {
  border-left: 1px solid var(--hairline);
}

.reader-view-toggle button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Scroll vs page-turn layouts */
.reader-viewport--scroll {
  scroll-snap-type: y mandatory;
}

.reader-viewport--turn {
  overflow: hidden;
  scroll-snap-type: none;
  align-items: center;
  justify-content: center;
  padding: 16px 32px 24px;
}

.reader-viewport--turn .reader-pages--scroll {
  display: none !important;
}

.reader-turn-host {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.reader-turn-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* One page cell — cover solo and each spread side share this exactly */
.reader-page-slot {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  width: calc(var(--reader-page-width) * var(--reader-display-scale));
  height: calc(var(--reader-page-height) * var(--reader-display-scale));
}

.reader-page-slot > .reader-sheet--display {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--reader-page-width);
  height: var(--reader-page-height);
  min-height: 0;
  max-height: var(--reader-page-height);
  transform: scale(var(--reader-display-scale));
  transform-origin: top left;
  box-shadow: none;
  border-radius: 0;
  overflow: hidden;
}

.reader-spread {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  width: calc(var(--reader-page-width) * 2 * var(--reader-display-scale));
  height: calc(var(--reader-page-height) * var(--reader-display-scale));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  flex-shrink: 0;
}

/* Page 1 front — same book chrome, one page wide, shown alone */
.reader-spread--solo-cover {
  width: calc(var(--reader-page-width) * var(--reader-display-scale));
}

.reader-spread--solo-cover .reader-sheet--cover-closed {
  cursor: pointer;
}

.reader-turn-stage .reader-sheet--display .reader-sheet__footer {
  flex-shrink: 0;
}

.reader-spread .reader-page-slot--left .reader-sheet--spread-left {
  border-right: 1px solid #d4d4d4;
}

/* Spine gutter on the page surface (spreads only — not front cover) */
.reader-spread:not(.reader-spread--solo-cover) .reader-page-slot > .reader-sheet--spread-left {
  box-shadow: inset -18px 0 22px -2px rgba(0, 0, 0, 0.08);
}

.reader-spread:not(.reader-spread--solo-cover) .reader-page-slot > .reader-sheet--spread-right {
  box-shadow: inset 18px 0 22px -2px rgba(0, 0, 0, 0.08);
}



.reader-sheet--cover-closed {
  box-shadow: none;
}

/* Cover page — full bleed (standard page size, not inset book-jacket ratio) */
.reader-sheet__body--cover {
  padding: 0 !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.reader-sheet__body--cover .reader-page__flow,
.reader-sheet__body--cover .reader-cover-page {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.reader-cover-page,
.reader-cover-page .reader-cover--fill,
.reader-sheet__body--cover .reader-cover--fill {
  flex: 1 1 0;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  aspect-ratio: unset;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.reader-sheet__body--cover .reader-cover__img {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  object-fit: cover;
  object-position: center;
  display: block;
}

.reader-sheet__body--cover .reader-cover__generated {
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* Turn-mode display clones: keep every page the same footprint */
.reader-turn-stage .reader-sheet--display .reader-sheet__body--cover,
.reader-turn-stage .reader-sheet--display .reader-sheet__body--blank,
.reader-turn-stage .reader-sheet--display .reader-sheet__body--title {
  height: 100%;
  min-height: 0;
}

.reader-sheet--placeholder {
  height: 100%;
}

/* Blank pages — same paper as content sheets */
.reader-sheet__body--blank {
  padding: 0 !important;
  background: #fff;
}

.reader-sheet--blank .reader-sheet__body {
  background: #fff;
}

/* Title page */
.reader-sheet__body--title {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.reader-title-page {
  width: 100%;
  max-width: 4.2in;
  margin: 0 auto;
}

.reader-title-page__title {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.15;
}

.reader-title-page__author {
  font-size: 1.05rem;
  font-style: italic;
  margin: 0 0 1.25rem;
  opacity: 0.88;
}

.reader-title-page__imprint {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.6;
  margin: 0 0 1.25rem;
}

.reader-title-page__meta {
  font-size: 0.78rem;
  line-height: 1.55;
  opacity: 0.65;
  margin: 0 0 1rem;
}

.reader-title-page__synopsis {
  font-size: 0.92rem;
  line-height: 1.5;
  text-align: left;
  margin: 1.5rem 0 0;
  opacity: 0.9;
}

.reader-sheet:has(.reader-bookmark),
.reader-sheet.reader-bookmark-target {
  overflow: visible;
}

.bookmark-recolor-filter {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

#bookmark-recolor feFlood {
  flood-color: var(--bookmark-color);
}

.bookmark-art {
  filter: url("#bookmark-recolor") drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.35));
}

.reader-bookmark {
  position: absolute;
  top: var(--bookmark-offset-y);
  width: var(--bookmark-width);
  height: auto;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-30px);
  transition:
    transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 0.35s ease;
}

.reader-bookmark__art {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.reader-bookmark-remove-icon {
  position: absolute;
  top: 6%;
  right: calc(50% - 15px);
  width: 53%;
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: 
color-mix(in srgb, #e3d9d9 88%, transparent);
  color: var(--danger);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  /* transform: translate(35%, -35%); */
  transition: opacity 0.15s ease;
}

.reader-bookmark-remove-icon:hover {
  background: color-mix(in srgb, var(--danger) 16%, var(--raised-bg, #1c1c1c));
  color: var(--danger);
}

.reader-bookmark:hover .reader-bookmark-remove-icon,
.reader-bookmark:focus-within .reader-bookmark-remove-icon {
  opacity: 1;
  pointer-events: auto;
}

.reader-bookmark--right {
  right: var(--bookmark-inset);
  left: auto;
}

.reader-bookmark--left {
  left: var(--bookmark-inset);
  right: auto;
}

.reader-bookmark.in {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.reader-bookmark.out {
  opacity: 0;
  transform: translateY(-30px);
}

.reader-bookmark:hover {
  transform: translateY(8px) !important;
}

.reader-bookmark:hover .reader-bookmark__art {
  opacity: 0.3;
}

.reader-sheet.reader-bookmark-target {
  cursor: pointer;
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, #c4a24a);
  outline-offset: -2px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.22),
    inset 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

body.reader-bookmark-placing {
  cursor: crosshair;
}
