/* Minimalist Template - Static Stylesheet */
/* Clean, modern design with full-screen layouts and no skeuomorphism */

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 16px;
  color: #1a1a1a;
  background: #f8f8f8;
}

h1, h2, h3 {
  font-family: var(--font-heading);
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: var(--primary-color);
}

/* ===== Book Container ===== */
.book {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f8f8;
}

/* ===== Pages ===== */
.page {
  position: absolute;
  inset: 0 0 56px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  transition: none;
}

.page[hidden] {
  display: none;
  pointer-events: none;
}

/* Page transition: slide */
.page.page--slide-in-next {
  z-index: 2;
  animation: slideInRight 0.35s ease forwards;
}

.page.page--slide-out-prev {
  z-index: 1;
  animation: slideOutLeft 0.35s ease forwards;
}

.page.page--slide-in-prev {
  z-index: 2;
  animation: slideInLeft 0.35s ease forwards;
}

.page.page--slide-out-next {
  z-index: 1;
  animation: slideOutRight 0.35s ease forwards;
}

/* Fallback fade for generic showPage calls */
.page.page--fade-in {
  z-index: 2;
  animation: fadeIn 0.3s ease forwards;
}

.page.page--fade-out {
  z-index: 1;
  animation: fadeOut 0.3s ease forwards;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

@keyframes slideOutLeft {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

@keyframes slideOutRight {
  from { transform: translateX(0); }
  to   { transform: translateX(100%); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ===== Cover ===== */
.page--cover {
  padding: 32px;
  text-align: center;
  background: #fff;
  color: #1a1a1a;
}

.cover-image-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
}

.cover-image-wrap img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.cover-text {
  flex-shrink: 0;
  padding: 16px 0 0;
}

.cover-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--primary-color);
}

.cover-subtitle {
  font-size: clamp(1rem, 3vw, 1.3rem);
  color: #555;
  margin-top: 8px;
}

.cover-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 50%;
  color: #555;
  transition: background 0.15s ease;
}

.btn-icon:active {
  background: #ddd;
  transform: scale(0.9);
}

/* ===== Content Pages ===== */
.page--content {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  background: #fff;
}

/* ===== Single Image Layout A (image left, text right) ===== */
.page--layout-a {
  flex-direction: row;
}

.page--layout-a .page-figure {
  flex: 1 1 55%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-a .page-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page--layout-a .page-body {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 4vw, 56px);
}

/* ===== Single Image Layout B (text left, image right) ===== */
.page--layout-b {
  flex-direction: row;
}

.page--layout-b .page-body {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 4vw, 56px);
}

.page--layout-b .page-figure {
  flex: 1 1 55%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-b .page-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Dual Image Layout A (images left stacked, text right) ===== */
.page--layout-2a {
  flex-direction: row;
}

.page--layout-2a .page-images-pair {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page--layout-2a .page-figure {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-2a .page-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page--layout-2a .page-body {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 4vw, 56px);
}

/* ===== Dual Image Layout: Portrait (side by side, each full height) ===== */
.page--layout-2portrait {
  flex-direction: row;
}

.page--layout-2portrait .page-images-pair {
  flex: 1 1 55%;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.page--layout-2portrait .page-figure {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-2portrait .page-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page--layout-2portrait .page-body {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 4vw, 56px);
}

/* ===== Dual Image Layout: Mixed/Flexible (stacked, object-fit contain) ===== */
.page--layout-2mixed {
  flex-direction: row;
}

.page--layout-2mixed .page-images-pair {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 4px;
}

.page--layout-2mixed .page-figure {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-2mixed .page-figure img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.page--layout-2mixed .page-body {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 4vw, 56px);
}

/* ===== Mixed Orientation: Portrait Left + Landscape/Text Right ===== */
.page--layout-pl {
  flex-direction: row;
}

.page--layout-pl .page-figure--portrait {
  flex: 0 0 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-pl .page-figure--portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page--layout-pl .page-right {
  flex: 1 1 60%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page--layout-pl .page-figure--landscape {
  flex: 1 1 50%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--background-color);
}

.page--layout-pl .page-figure--landscape img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page--layout-pl .page-body {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(16px, 3vw, 40px);
}

/* ===== Shared figure styles ===== */
.page-figure figcaption {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.4);
  padding: 2px 8px;
  border-radius: 4px;
}

.page-figure {
  position: relative;
}

/* ===== Page text ===== */
.page-text {
  font-size: var(--page-text-size);
  line-height: var(--page-text-line-height);
  color: #2a2a2a;
}

/* ===== Extras ===== */
.extras {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.extra {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--background-color);
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  color: #333;
  transition: transform 0.15s ease, background 0.15s ease;
}

.extra:active {
  transform: scale(0.95);
  background: #e8e8e8;
}

.extra-icon {
  font-size: 1em;
}

.extra[data-audio] {
  position: relative;
  z-index: 30;
  pointer-events: auto;
}

/* ===== Read-to-Me Button ===== */
.btn-read {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-color);
  color: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: transform 0.15s ease;
  z-index: 30;
  pointer-events: auto;
}

.btn-read:active {
  transform: scale(0.88);
}

.btn-read.playing {
  background: var(--accent-color);
  animation: pulse-read 1s infinite;
}

@keyframes pulse-read {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0.1); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

/* ===== Bottom Navigation Bar ===== */
.nav-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 112px;
  background: #fff;
  border-top: 1px solid #e8e8e8;
  z-index: 10;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.nav-bar-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  color: #333;
  border-radius: 50%;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.nav-bar-btn:active {
  transform: scale(0.88);
  background: #e0e0e0;
}

.btn-home {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 25;
}

.nav-bar-prev[hidden],
.nav-bar-next[hidden] {
  display: flex;
  visibility: hidden;
}

/* ===== Mobile Tap Zones ===== */
.tap-zone {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  min-width: 64px;
  z-index: 10;
}

.tap-zone--left { left: 0; }
.tap-zone--right { right: 0; }

.tap-zone.ripple::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.04);
  animation: tap-ripple 0.35s ease-out forwards;
  pointer-events: none;
}

@keyframes tap-ripple {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== Swipe Hint ===== */
.swipe-hint {
  display: none;
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 20;
  pointer-events: none;
  animation: hint-fade 3s ease forwards;
}

.swipe-hint-hand {
  font-size: 2rem;
  animation: hint-sway 1.2s ease-in-out infinite;
}

.swipe-hint-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  background: rgba(255,255,255,0.9);
  padding: 4px 12px;
  border-radius: 12px;
}

@keyframes hint-sway {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-16px); }
}

@keyframes hint-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== Credits Page ===== */
.page--credits {
  padding: 32px;
  overflow-y: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

.credits-content {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.credits-title {
  font-size: 1.5rem;
  color: var(--primary-color);
  margin-bottom: 16px;
}

.credits-content h3 {
  font-size: 1rem;
  color: #555;
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.credits-sources, .credits-images {
  list-style: none;
  padding: 0;
}

.credits-sources li, .credits-images li {
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 3px 0;
  color: #444;
}

.credits-footer {
  margin-top: 24px;
  font-size: 0.9rem;
  color: #999;
}

/* ===== Portrait / Mobile (stacked) ===== */
@media (orientation: portrait), (max-width: 700px) {
  .page--content {
    flex-direction: column;
  }

  .page--layout-a .page-figure,
  .page--layout-b .page-figure {
    order: 1;
    flex: 1 1 var(--portrait-image-share);
    width: 100%;
  }

  .page--layout-a .page-body,
  .page--layout-b .page-body {
    order: 2;
    flex: 0 1 var(--portrait-text-share);
    width: 100%;
    padding: 16px 20px;
  }

  .page--layout-2a .page-images-pair {
    flex: 1 1 var(--portrait-image-share);
    width: 100%;
    flex-direction: row;
  }

  .page--layout-2a .page-body {
    flex: 0 1 var(--portrait-text-share);
    width: 100%;
    padding: 16px 20px;
  }

  .page--layout-2portrait .page-images-pair {
    flex: 1 1 var(--portrait-image-share);
    width: 100%;
    flex-direction: row;
  }

  .page--layout-2portrait .page-body {
    flex: 0 1 var(--portrait-text-share);
    width: 100%;
    padding: 16px 20px;
  }

  .page--layout-2mixed .page-images-pair {
    flex: 1 1 var(--portrait-image-share);
    width: 100%;
    flex-direction: row;
  }

  .page--layout-2mixed .page-body {
    flex: 0 1 var(--portrait-text-share);
    width: 100%;
    padding: 16px 20px;
  }

  .page--layout-pl {
    flex-direction: column;
  }

  .page--layout-pl .page-figure--portrait {
    flex: 0 0 auto;
    width: 100%;
    height: 35%;
  }

  .page--layout-pl .page-right {
    flex: 1 1 auto;
    width: 100%;
  }

  .page--layout-pl .page-figure--landscape {
    flex: 1 1 50%;
  }

  .page--layout-pl .page-body {
    flex: 1 1 50%;
    padding: 12px 20px;
  }
}

/* ===== Responsive: Mobile (<480px) ===== */
@media (max-width: 479px) {
  .tap-zone {
    display: block;
  }

  .swipe-hint {
    display: flex;
  }

  .cover-actions {
    top: 8px;
    right: 8px;
  }

  .btn-read {
    bottom: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
  }

  .page--credits {
    padding: 16px;
  }

  .nav-bar {
    gap: 92px;
  }

  .nav-bar-btn {
    width: 44px;
    height: 44px;
  }
}

/* ===== Responsive: Tablet & Desktop ===== */
@media (min-width: 480px) {
  .swipe-hint {
    display: none;
  }
}

/* ===== Landscape on small phones ===== */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 700px) {
  .page--content {
    flex-direction: row;
  }

  .page--layout-a .page-figure,
  .page--layout-b .page-figure {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
  }

  .page--layout-a .page-body,
  .page--layout-b .page-body {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    padding: 12px 16px;
  }

  .page--layout-2a .page-images-pair {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    flex-direction: column;
  }

  .page--layout-2a .page-body {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    padding: 12px 16px;
  }

  .page--layout-2portrait .page-images-pair {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    flex-direction: row;
  }

  .page--layout-2portrait .page-body {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    padding: 12px 16px;
  }

  .page--layout-2mixed .page-images-pair {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    flex-direction: column;
  }

  .page--layout-2mixed .page-body {
    flex: 1 1 50%;
    width: auto;
    height: 100%;
    padding: 12px 16px;
  }

  .page--layout-pl {
    flex-direction: row;
  }

  .page--layout-pl .page-figure--portrait {
    flex: 0 0 30%;
    height: 100%;
  }

  .page--layout-pl .page-right {
    flex: 1 1 70%;
    height: 100%;
  }

  .btn-read {
    bottom: 8px;
    right: 56px;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  .page.page--slide-in-next,
  .page.page--slide-out-prev,
  .page.page--slide-in-prev,
  .page.page--slide-out-next,
  .page.page--fade-in,
  .page.page--fade-out {
    animation-duration: 0.1s;
  }

  .btn-read,
  .extra,
  .nav-bar-btn,
  .btn-icon {
    transition: none;
  }

  .btn-read.playing {
    animation: none;
  }

  .swipe-hint-hand {
    animation: none;
  }
}

/* ===== Print ===== */
@media print {
  html, body {
    height: auto;
    overflow: visible;
    background: #fff;
  }

  .book {
    position: static;
    display: block;
    padding: 0;
    background: none;
  }

  .page {
    position: static;
    display: flex !important;
    flex-direction: column;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    page-break-after: always;
    padding: 24px;
    min-height: 0;
    height: auto;
    inset: auto;
    box-shadow: none;
    animation: none !important;
  }

  .page[hidden] {
    display: flex !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
  }

  .page-figure,
  .page-body,
  .page-images-pair {
    position: static;
    width: 100%;
    height: auto;
  }

  .page-figure {
    break-inside: avoid;
  }

  .nav-bar,
  .tap-zone,
  .swipe-hint,
  .btn-read,
  .cover-actions,
  .btn-print,
  .btn-home {
    display: none !important;
  }

  .page--cover {
    background: none !important;
    color: #1a1a1a;
  }
}
