/* Playmat Template - bright, tactile, touch-first nonfiction */

*, *::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: #243032;
  background: #f7f1df;
}

h1, h2, h3 { font-family: var(--font-heading); }
img { display: block; max-width: 100%; height: auto; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
a { color: var(--primary-color); }

.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:
    linear-gradient(90deg, rgba(255,255,255,0.34) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.34) 1px, transparent 1px),
    radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--secondary-color) 34%, transparent), transparent 24%),
    radial-gradient(circle at 82% 76%, color-mix(in srgb, var(--accent-color) 30%, transparent), transparent 26%),
    linear-gradient(135deg, #fff4c8, #d9f4ea 48%, #ffe1df);
  background-size: 42px 42px, 42px 42px, auto, auto, auto;
}

.page {
  position: absolute;
  inset: clamp(8px, 2vw, 22px) clamp(10px, 4vw, 74px);
  display: flex;
  overflow: hidden;
  background: #fffaf0;
  border: 5px solid rgba(255,255,255,0.9);
  border-radius: 22px;
  box-shadow: 0 18px 40px rgba(41, 49, 50, 0.18);
}

.page[hidden] { display: none; pointer-events: none; }
.page--slide-in-next { z-index: 2; animation: bounceInRight 0.42s cubic-bezier(.2,.9,.3,1.1) both; }
.page--slide-out-prev { z-index: 1; animation: nudgeOutLeft 0.32s ease both; }
.page--slide-in-prev { z-index: 2; animation: bounceInLeft 0.42s cubic-bezier(.2,.9,.3,1.1) both; }
.page--slide-out-next { z-index: 1; animation: nudgeOutRight 0.32s ease both; }
.page--fade-in { z-index: 2; animation: fadeIn 0.2s ease both; }
.page--fade-out { z-index: 1; animation: fadeOut 0.2s ease both; }

@keyframes bounceInRight { from { transform: translateX(104%) scale(.98); } 76% { transform: translateX(-2%) scale(1); } to { transform: translateX(0); } }
@keyframes nudgeOutLeft { from { transform: translateX(0); } to { transform: translateX(-104%) rotate(-1deg); } }
@keyframes bounceInLeft { from { transform: translateX(-104%) scale(.98); } 76% { transform: translateX(2%) scale(1); } to { transform: translateX(0); } }
@keyframes nudgeOutRight { from { transform: translateX(0); } to { transform: translateX(104%) rotate(1deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.page--cover {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vh, 18px);
  padding: clamp(18px, 4vw, 34px);
  text-align: center;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--background-color) 72%, white), #fff8dc),
    var(--background-color);
}

.cover-image-wrap {
  flex: 0 0 auto;
  min-height: 0;
  width: min(76vw, 600px);
  height: clamp(260px, 50vh, 440px);
  display: grid;
  place-items: center;
  padding: clamp(8px, 1.5vw, 14px);
  background: #fff;
  border: 8px solid color-mix(in srgb, var(--secondary-color) 50%, white);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 10px 0 color-mix(in srgb, var(--primary-color) 20%, transparent);
}

.cover-image-wrap img { width: 100%; height: 100%; object-fit: contain; border-radius: 18px; }
.cover-text { flex-shrink: 0; max-width: min(92vw, 740px); }
.cover-title { font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1.05; color: var(--primary-color); }
.cover-subtitle { margin-top: 6px; font-size: clamp(1rem, 2.4vw, 1.35rem); color: #344345; font-weight: 700; }
.cover-actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.btn-icon, .nav-edge-btn {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--primary-color);
  border-radius: 18px;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--primary-color) 62%, #111);
  text-decoration: none;
}

.btn-icon:active, .nav-edge-btn:active { transform: translateY(4px) scale(.96); box-shadow: 0 1px 0 color-mix(in srgb, var(--primary-color) 62%, #111); }

.page--content { flex-direction: row; align-items: stretch; gap: clamp(10px, 1.8vw, 18px); padding: clamp(12px, 2vw, 22px); }
.page--content::before { content: ""; position: absolute; inset: 12px; border: 3px dashed color-mix(in srgb, var(--accent-color) 55%, white); border-radius: 16px; pointer-events: none; opacity: .55; }

.page-figure, .page-images-pair, .page-body, .page-right { position: relative; min-width: 0; min-height: 0; }
.page-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: color-mix(in srgb, var(--secondary-color) 28%, white);
  border: 5px solid #fff;
  border-radius: 20px;
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--secondary-color) 45%, white), 0 10px 18px rgba(28,38,38,.12);
}

.page-figure img { width: 100%; height: 100%; object-fit: cover; }
.page--layout-2mixed .page-figure img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.page-figure figcaption { position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px); padding: 4px 9px; border-radius: 999px; background: rgba(255,255,255,.9); color: #243032; font-size: .68rem; font-weight: 700; }

.page-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(18px, 3.4vw, 46px);
  background: color-mix(in srgb, var(--background-color) 48%, white);
  border-radius: 22px;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.62);
}

.page-text { font-size: var(--page-text-size); line-height: var(--page-text-line-height); color: #243032; font-weight: 700; }
.extras { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.extra { min-height: 44px; display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 15px; background: #fff; color: #243032; font-weight: 800; font-size: .92rem; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent-color) 38%, #c7c7c7); }
.extra:active { transform: translateY(3px) scale(.98); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent-color) 38%, #c7c7c7); }
.extra-icon { width: .7em; height: .7em; border-radius: 50%; background: var(--accent-color); color: transparent; }

.page--layout-a .page-figure, .page--layout-b .page-figure, .page--layout-2a .page-images-pair, .page--layout-2portrait .page-images-pair, .page--layout-2mixed .page-images-pair { flex: 1 1 58%; }
.page--layout-a .page-body, .page--layout-b .page-body, .page--layout-2a .page-body, .page--layout-2portrait .page-body, .page--layout-2mixed .page-body { flex: 1 1 42%; }
.page--layout-b { flex-direction: row; }
.page--layout-2a .page-images-pair, .page--layout-2mixed .page-images-pair { display: flex; flex-direction: column; gap: clamp(8px, 1.4vw, 14px); }
.page--layout-2portrait .page-images-pair { display: flex; flex-direction: row; gap: clamp(8px, 1.4vw, 14px); }
.page--layout-pl .page-figure--portrait { flex: 0 0 38%; }
.page--layout-pl .page-right { flex: 1 1 62%; display: flex; flex-direction: column; gap: clamp(8px, 1.4vw, 14px); }
.page--layout-pl .page-figure--landscape, .page--layout-pl .page-body { flex: 1 1 0; }

.extra[data-audio] { position: relative; z-index: 30; pointer-events: auto; }
.btn-read { position: absolute; right: 20px; bottom: 20px; z-index: 30; pointer-events: auto; width: 58px; height: 58px; display: flex; align-items: center; justify-content: center; border-radius: 19px; background: var(--accent-color); color: #172224; box-shadow: 0 5px 0 color-mix(in srgb, var(--accent-color) 55%, #555); }
.btn-read:active { transform: translateY(4px) scale(.96); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent-color) 55%, #555); }
.btn-read.playing { animation: playPulse 1s ease-in-out infinite; }
@keyframes playPulse { 50% { transform: scale(1.06); } }

.nav-edge { position: absolute; inset: 0; z-index: 25; pointer-events: none; }
.nav-edge-btn { position: absolute; pointer-events: auto; }
.nav-edge-prev { left: max(10px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); }
.nav-edge-next { right: max(10px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); }
.nav-edge-prev:active, .nav-edge-next:active { transform: translateY(-50%) scale(.96); }
.nav-edge-home { left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); width: 50px; height: 50px; }
.nav-edge-prev[hidden], .nav-edge-next[hidden] { display: flex; visibility: hidden; }
.tap-zone { display: none; position: absolute; top: 0; bottom: 0; width: 22%; min-width: 64px; z-index: 12; }
.tap-zone--left { left: 0; } .tap-zone--right { right: 0; }
.tap-zone.ripple::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--accent-color) 30%, transparent); animation: tapRipple .35s ease-out both; }
@keyframes tapRipple { from { opacity: 1; } to { opacity: 0; } }
.swipe-hint { display: none; position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; pointer-events: none; text-align: center; }
.swipe-hint-hand { display: inline-block; padding: 8px 13px; border-radius: 999px; background: #fff; color: var(--primary-color); font-family: var(--font-heading); font-weight: 800; box-shadow: 0 4px 12px rgba(0,0,0,.12); animation: hintSway 1.2s ease-in-out infinite; }
.swipe-hint-label { display: block; margin-top: 5px; color: #243032; font-size: .8rem; font-weight: 800; }
@keyframes hintSway { 50% { transform: translateX(-14px); } }

.page--credits {
  padding: max(clamp(18px, 4vw, 42px), 76px) clamp(18px, 4vw, 42px) clamp(18px, 4vw, 42px) max(clamp(18px, 4vw, 42px), calc(78px + env(safe-area-inset-left)));
  overflow: hidden;
  align-items: flex-start;
  justify-content: flex-start;
}
.credits-content { width: min(920px, 100%); height: 100%; margin: 0 auto; padding: clamp(14px, 2.4vw, 24px); overflow: hidden; background: #fff; border-radius: 22px; box-shadow: 0 10px 24px rgba(0,0,0,.1); }
.credits-title { color: var(--primary-color); font-size: clamp(1.35rem, 3.2vw, 2rem); line-height: 1.05; margin-bottom: clamp(8px, 1.5vw, 12px); }
.credits-content h3 { margin: 10px 0 6px; color: #344345; font-size: 1rem; }
.credits-sources, .credits-images { list-style: none; }
.credits-sources, .credits-images { display: grid; gap: clamp(5px, 1vw, 8px) clamp(12px, 2vw, 20px); }
.credits-sources { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.credits-images { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.credits-sources li, .credits-images li { padding: 0; color: #344345; font-size: clamp(.8rem, 1.25vw, .92rem); line-height: 1.25; }
.credits-images strong { display: block; color: #243032; }

@media (orientation: portrait), (max-width: 700px) {
  .page { inset: 6px; border-radius: 18px; }
  .page--content, .page--layout-b, .page--layout-pl { flex-direction: column; gap: 8px; padding: 10px; }
  .page--layout-a .page-figure, .page--layout-b .page-figure, .page--layout-2a .page-images-pair, .page--layout-2portrait .page-images-pair, .page--layout-2mixed .page-images-pair { flex: 1 1 var(--portrait-image-share); width: 100%; }
  .page--layout-a .page-body, .page--layout-b .page-body, .page--layout-2a .page-body, .page--layout-2portrait .page-body, .page--layout-2mixed .page-body { flex: 0 1 var(--portrait-text-share); width: 100%; padding: 14px 16px; }
  .page--layout-2a .page-images-pair, .page--layout-2portrait .page-images-pair, .page--layout-2mixed .page-images-pair { flex-direction: row; }
  .page--layout-pl .page-figure--portrait { flex: 0 0 30%; width: 100%; }
  .page--layout-pl .page-right { flex: 1 1 70%; width: 100%; }
  .page--layout-pl .page-figure--landscape { flex: 1 1 48%; }
  .page--layout-pl .page-body { flex: 1 1 52%; padding: 12px 16px; }
  .extras { gap: 6px; margin-top: 10px; }
  .extra { min-height: 38px; padding: 7px 10px; font-size: .82rem; }
  .page--credits { padding-left: max(76px, calc(76px + env(safe-area-inset-left))); }
  .credits-content { padding: 12px; }
  .credits-sources, .credits-images { grid-template-columns: 1fr; gap: 5px; }
  .credits-sources li, .credits-images li { font-size: clamp(.72rem, 2.5vw, .85rem); line-height: 1.18; }
}

@media (max-width: 479px) {
  .nav-edge .nav-edge-prev, .nav-edge .nav-edge-next { display: none; }
  .tap-zone, .swipe-hint { display: block; }
  .cover-actions { top: 8px; right: 8px; }
  .btn-icon { width: 46px; height: 46px; border-radius: 15px; }
  .btn-read { width: 50px; height: 50px; right: 12px; bottom: 12px; }
  .page-text { line-height: var(--page-text-line-height); }
  .page--content::before { display: none; }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 700px) {
  .page--content, .page--layout-b { flex-direction: row; }
  .page--layout-a .page-figure, .page--layout-b .page-figure, .page--layout-2a .page-images-pair, .page--layout-2portrait .page-images-pair, .page--layout-2mixed .page-images-pair { flex: 1 1 54%; height: 100%; }
  .page--layout-a .page-body, .page--layout-b .page-body, .page--layout-2a .page-body, .page--layout-2portrait .page-body, .page--layout-2mixed .page-body { flex: 1 1 46%; height: 100%; padding: 10px 14px; }
  .page--layout-2a .page-images-pair, .page--layout-2mixed .page-images-pair { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  .book { position: static; display: block; padding: 0; background: none; }
  .page, .page[hidden] { position: static; display: flex !important; inset: auto; height: auto; min-height: 0; page-break-after: always; padding: 24px; border: 0; border-radius: 0; box-shadow: none; transform: none !important; animation: none !important; }
  .page--content { flex-direction: column; }
  .page-figure, .page-body, .page-images-pair { break-inside: avoid; width: 100%; height: auto; }
  .nav-edge, .tap-zone, .swipe-hint, .btn-read, .cover-actions { display: none !important; }
}
