/* Portrait layout: 3D flip pages (image + story stacked) */

body.layout-portrait .book-wrapper {
  display: none;
}

body.layout-landscape .portrait-card {
  display: none !important;
}

.portrait-card {
  display: none;
  position: relative;
  width: 100%;
  max-width: min(100cqw, 440px);
  height: 100%;
  max-height: 100cqh;
  margin: 0 auto;
  align-self: center;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  perspective: 1800px;
  perspective-origin: 50% 50%;
  z-index: 3;
}

body.layout-portrait .portrait-card {
  display: block;
}

body.layout-portrait .stage {
  align-items: stretch;
  justify-content: center;
  padding: 0.25rem 0.5rem;
}

.portrait-pages {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.portrait-page {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--flip-duration) ease-in-out;
  will-change: transform;
}

.portrait-page.flipped {
  transform: rotateY(-180deg);
}

.portrait-page.flipping {
  z-index: 300 !important;
  pointer-events: none;
}

.portrait-page.flipping .portrait-page-face--front {
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    -8px 4px 20px rgba(0, 0, 0, 0.35);
}

.portrait-page-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--page-bg);
  border: 1px solid var(--page-border);
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    2px 2px 8px var(--page-shadow);
  overflow: hidden;
}

.portrait-page-face--back {
  transform: rotateY(180deg);
  background: var(--page-bg-dark);
}

.portrait-cover {
  position: absolute;
  inset: 0;
  z-index: 150;
  background: var(--page-bg);
  border: 1px solid var(--page-border);
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    2px 4px 16px var(--page-shadow);
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition:
    transform var(--open-duration) ease-in-out,
    opacity var(--open-duration) ease;
}

.portrait-card--closed .portrait-cover {
  transform: rotateY(0deg);
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.portrait-card--opening .portrait-cover,
.portrait-card--open .portrait-cover {
  transform: rotateY(-105deg);
  opacity: 0;
  pointer-events: none;
}

.portrait-card--closing .portrait-cover {
  transform: rotateY(0deg);
  opacity: 1;
  transition:
    transform var(--open-duration) ease-in-out,
    opacity calc(var(--open-duration) * 0.6) ease;
}

.portrait-card--closed-back::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(225deg, rgba(139, 105, 20, 0.06) 0%, transparent 50%),
    var(--page-bg-dark);
  border: 1px solid var(--page-border);
  z-index: 1;
  pointer-events: none;
}

.portrait-card__back {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
  background: var(--page-bg-dark);
}

.portrait-card__back p {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
  letter-spacing: 0.2em;
}

.portrait-card__spread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.portrait-card__image {
  flex: 0 0 38%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  background: var(--page-bg);
  border-bottom: 1px solid var(--page-border);
  position: relative;
}

body.viewport-narrow .portrait-card__image {
  flex: 0 0 32%;
  padding: 0.4rem 0.5rem;
}

.portrait-card__image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.portrait-card__image .specimen-label {
  position: absolute;
  bottom: 0.35rem;
  left: 0.5rem;
  right: 0.5rem;
  text-align: center;
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.portrait-card__story {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(0.5rem, 2vw, 0.85rem);
  background: var(--page-bg-dark);
  overflow: hidden;
}

.portrait-card__story .story-header {
  flex-shrink: 0;
  margin-bottom: 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--page-border);
}

.portrait-card__story .story-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  font-size: clamp(0.82rem, 3.2vw, 0.92rem);
  line-height: 1.75;
  text-align: justify;
  color: var(--text-primary);
}

@media (prefers-reduced-motion: reduce) {
  .portrait-page,
  .portrait-cover {
    transition: none;
  }
}
