/* Shell stays painted. Splash overlays only as a fallback after ~1s. */
#home-loading {
  display: none;
}

#author-view.is-public-record-missing .author-detail-layout,
#author-view.is-public-record-missing .compact-entity-identity,
#book-view.is-public-record-missing .book-detail-layout,
#book-view.is-public-record-missing .compact-entity-identity {
  display: none;
}

html.home-booting,
html.home-booting body {
  min-width: 0;
}

html.home-booting.loading-visible #home-loading {
  display: grid;
  place-items: center;
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  padding: 24px;
  box-sizing: border-box;
  background: #fff;
  color: #242424;
  font: 15px / 1.5 var(--font-body, system-ui, sans-serif);
}

/* Keep the shell silent until the splash threshold — no early status strip. */
html.home-booting:not(.loading-visible) #home-loading {
  display: none;
}

.home-splash {
  position: relative;
  width: clamp(148px, 54vw, 204px);
  aspect-ratio: 1;
  --duration: 1.8s;
  --step: 220ms;
  --lift: -6px;
}

.home-splash-book {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

html.home-booting.loading-visible:not(.home-loading-error) .home-splash-book {
  animation: home-splash-book-wave var(--duration) ease-in-out infinite;
}

html.home-booting.loading-visible:not(.home-loading-error)
  .home-splash-book:nth-of-type(2) {
  animation-delay: var(--step);
}

html.home-booting.loading-visible:not(.home-loading-error)
  .home-splash-book:nth-of-type(3) {
  animation-delay: calc(2 * var(--step));
}

@keyframes home-splash-book-wave {
  0%,
  45%,
  100% {
    transform: translateY(0);
  }
  22% {
    transform: translateY(var(--lift));
  }
}

@media (prefers-reduced-motion: reduce) {
  html.home-booting.loading-visible .home-splash-book {
    animation: none;
  }
}

.home-loading-status {
  position: absolute;
  top: calc(50% + clamp(74px, 27vw, 102px));
  inset-inline: 24px;
  margin: 0;
  text-align: center;
  color: #555;
  font-size: 15px;
  line-height: 1.5;
}

#home-loading button {
  position: absolute;
  top: calc(50% + clamp(110px, 34vw, 140px));
  justify-self: center;
}

#home-loading button[hidden] {
  display: none;
}

#home-loading [data-loading-title] {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  inset-inline: 24px;
  margin: 0;
  text-align: center;
  font: var(--weight-semibold, 600) var(--type-panel-size, 20px) /
    var(--type-panel-line, 1.3) var(--font-head, Literata, Georgia, serif);
  color: #242424;
}

html.home-loading-error .home-splash {
  opacity: 0.35;
}

/* SPA region waits: only real failures surface a toast. */
.catalog-loading-status {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 90px;
  z-index: 120;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: auto;
  padding: 12px 18px;
  border-radius: var(--radius-panel, 18px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #242424);
  box-shadow: 0 2px 14px #0002;
  font: 14px / 1.5 var(--font-body, system-ui, sans-serif);
}

.catalog-loading-status[hidden] {
  display: none;
}

.catalog-page-placeholder {
  min-height: 112px;
  border-radius: var(--radius-panel, 18px);
  background: var(--color-border, #e8e8e8);
}

.books-grid > .catalog-page-placeholder {
  aspect-ratio: 2 / 3;
}

.catalog-loading-progress:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: none;
}

.catalog-loading-progress::before {
  content: "";
  inline-size: 1em;
  block-size: 1em;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: catalog-loading-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .catalog-loading-progress::before { animation: none; }
}

.cover-waiting {
  background: var(--color-border, #e8e8e8);
}


.screen-loading-region {
  margin-block: 16px;
}

.screen-loading-region > .catalog-loading-status,
.ser-detail-profile > .catalog-loading-status {
  position: static;
  width: auto;
  max-width: none;
  margin: 0 0 12px;
  box-shadow: none;
}

/* Personal home uses the final layout during boot and keeps error status local. */
html[data-personal-home-boot].home-booting #home-loading,
.home-reading-skeleton[hidden],
.home-recommendation-skeleton[hidden],
#home-reads-grid[hidden] {
  display: none !important;
}

html[data-personal-home-boot].home-booting:is(.loading-visible, .home-loading-error) #reading-carousel > #home-loading {
  position: absolute;
  inset: auto 12px 12px;
  z-index: 3;
  display: grid !important;
  justify-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-panel);
  background: var(--color-surface);
  color: var(--color-text);
}

html[data-personal-home-boot] #reading-carousel {
  position: relative;
}

html[data-personal-home-boot] #home-loading :is(.home-splash, [data-loading-title]) {
  display: none;
}

html[data-personal-home-boot] #home-loading :is(.home-loading-status, button) {
  position: static;
}

html[data-personal-home-boot].home-booting #reading-carousel > .home-reading-skeleton {
  display: grid !important;
}

html[data-personal-home-boot].home-booting #reading-carousel > :is(.home-reading-initial, .capture-empty-reading, #mobile-reading-rail, .next-book-peek) {
  display: none !important;
}

.home-loading-announcement {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.home-skeleton-line {
  display: block;
  width: min(100%, 15rem);
  min-height: 14px;
  border-radius: var(--radius-sm);
  background: var(--soft);
}

.home-reading-skeleton .home-skeleton-line {
  background: var(--soft);
}

.home-reading-skeleton .focus-copy .home-skeleton-line:first-child {
  min-height: 30px;
  margin-bottom: 14px;
}

.home-reading-skeleton .focus-copy .home-skeleton-line:last-child {
  width: min(65%, 9rem);
}

.home-reading-skeleton .reading-controls .home-skeleton-line {
  width: 7rem;
  min-height: 38px;
}

html[data-personal-home-boot].home-booting .home-calendar-skeleton {
  flex: 1;
  min-height: 240px;
  border-radius: var(--radius-sm);
  background:
    repeating-linear-gradient(to right, transparent 0 calc(100% / 7 - 2px), var(--color-surface) calc(100% / 7 - 2px) calc(100% / 7)),
    repeating-linear-gradient(to bottom, var(--soft) 0 calc(100% / 5 - 2px), var(--color-surface) calc(100% / 5 - 2px) calc(100% / 5));
}

html[data-personal-home-boot].home-booting .home-recommendation-skeleton {
  display: grid !important;
}

.home-recommendation-skeleton .is-compact {
  min-height: 100px;
}

.home-header-placeholder { display: none; }

html[data-personal-home-boot].home-responsive .topbar-actions:not(:has(#capture-global-trigger)) > .home-add-placeholder,
html[data-personal-home-boot].home-responsive .compact-home-actions:not(:has(#capture-global-trigger)) > .home-add-placeholder,
html[data-personal-home-boot].home-responsive .compact-home-actions:not(:has(#profile-menu-trigger)) > .home-profile-placeholder,
html[data-personal-home-boot][data-catalog-admin].home-responsive .topbar-actions:not(:has(#header-admin-entry:not([hidden]))) > .home-admin-placeholder {
  display: block;
  flex: 0 0 var(--control-height-icon, 36px);
  width: var(--control-height-icon, 36px);
  height: var(--control-height-icon, 36px);
  border-radius: 50%;
  background: var(--soft);
}

@media (max-width: 1199px) {
  html.home-responsive #reading-carousel > .home-reading-skeleton {
    --home-hero-gap: 28px;
    --home-hero-center-width: min(248px, calc(0.9775 * (100cqi - 2 * var(--home-hero-gap)) / 2.15));
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 8px;
  }

  html.home-responsive #reading-carousel .home-reading-skeleton .book-placeholder {
    width: var(--home-hero-center-width);
    height: auto;
    justify-self: center;
    background: var(--surface-secondary);
  }

  html.home-responsive #reading-carousel .home-reading-skeleton .reading-controls {
    grid-column: 1;
    grid-row: 2;
    margin-top: 6px;
  }

  .compact-home-actions .home-add-placeholder { order: -1; }
  .compact-home-actions .home-profile-placeholder { order: 1; }
}
