:root {
  color-scheme: dark;
  --background: #070c19;
  --text: #f2eee7;
  --muted: #9aabbf;
  --accent: #d9e7b6;
  --line: rgb(192 207 229 / 15%);
  --page-width: min(40vw, 460px, max(140px, calc((100svh - 190px) / 1.4)));
  --turn-duration: 850ms;
  font-family: Inter, "Avenir Next", Avenir, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  color: var(--text);
  background: radial-gradient(ellipse at center, #131d2d, var(--background) 75%);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}
button svg { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: 24px 20px;
}
.card-viewer { width: 100%; max-width: 1060px; }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(var(--page-width) * 1.4 + 20px);
  padding-block: 10px;
  perspective: 2200px;
  isolation: isolate;
  /* Prevent browser back/forward gestures from stealing a horizontal page swipe. */
  touch-action: pan-y pinch-zoom;
}
.book {
  position: relative;
  width: var(--page-width);
  aspect-ratio: 5 / 7;
  transform-style: preserve-3d;
  transition: transform var(--turn-duration) cubic-bezier(.32, .02, .2, 1);
}
.leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--turn-duration) cubic-bezier(.32, .02, .2, 1);
}
.front-leaf { z-index: 2; }
.back-leaf { z-index: 1; }
.leaf.turning { z-index: 5 !important; }
.face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  border-radius: 3px 5px 5px 3px;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 15px 50px rgb(0 0 0 / 45%), 0 0 0 1px rgb(255 255 255 / 12%);
  overflow: hidden;
}
.face-back { transform: rotateY(180deg); border-radius: 5px 3px 3px 5px; }
.face img, .mobile-page img { width: 100%; height: 100%; display: block; object-fit: contain; user-select: none; }
/* The shading sits on top of the artwork without changing or cropping it. */
.face::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgb(0 0 0 / 12%), transparent 4%, transparent 97%, rgb(0 0 0 / 4%)); }
.face-back::after { background: linear-gradient(90deg, transparent 94%, rgb(0 0 0 / 15%)); }
.stage[data-view="inside"] .book { transform: translateX(50%); }
.stage[data-view="inside"] .front-leaf,
.stage[data-view="back"] .front-leaf,
.stage[data-view="back"] .back-leaf { transform: rotateY(-180deg); }
.stage[data-view="back"] .book { transform: translateX(100%); }
.stage[data-view="back"] .back-leaf { z-index: 3; }

.navigation { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; width: min(100%, 440px); margin: 16px auto 0; }
.page-label { font-size: .8rem; color: var(--muted); text-align: center; }
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 8px 0; border: 0; background: none; color: var(--muted); font-size: .75rem; transition: color 160ms; }
.text-button:hover { color: var(--text); }
.next-button { display: flex; align-items: center; justify-self: end; gap: 10px; min-height: 44px; padding: 8px 0 8px 8px; border: 0; background: none; color: var(--text); font-size: .8rem; white-space: nowrap; transition: color 160ms, opacity 160ms; }
.next-button:hover { color: var(--accent); }
.next-button:disabled { opacity: .45; }
.next-button svg { width: 18px; height: 18px; }
.arrow-button { display: grid; place-items: center; justify-self: start; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: none; color: #bdcad8; transition: border-color 180ms, opacity 180ms, background 180ms; }
.arrow-button:not(:disabled):hover { border-color: #8698a7; background: rgb(255 255 255 / 5%); }
.arrow-button:disabled { opacity: .23; }
.reader-tools { display: flex; justify-content: center; gap: 24px; margin-top: 6px; }

.transcript { width: 100%; max-width: 740px; margin-top: 24px; }
.transcript-content { padding: 24px; background: rgb(255 255 255 / 3%); border: 1px solid var(--line); border-radius: 6px; font-size: .9rem; line-height: 1.8; color: #bcc9d8; }
.transcript-content h2 { font-size: 1rem; font-weight: 600; color: var(--text); margin: 28px 0 8px; }
.transcript-content h2:first-child { margin-top: 0; }
.transcript-content p { margin-block: 10px; }
.transcript-content ul { padding-left: 20px; }
.transcript-content li { margin-bottom: 8px; }

.art-dialog { width: min(96vw, 1440px); max-width: none; max-height: 96dvh; padding: 0; border: 1px solid #303c50; border-radius: 8px; background: #0c1322; color: var(--text); overflow: hidden; box-shadow: 0 30px 100px rgb(0 0 0 / 60%); }
.art-dialog[open] { display: flex; flex-direction: column; }
.art-dialog::backdrop { background: rgb(2 5 13 / 90%); backdrop-filter: blur(8px); }
.dialog-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; flex-shrink: 0; border-bottom: 1px solid var(--line); }
.dialog-toolbar h2 { margin: 0; font-size: .85rem; font-weight: 500; }
.dialog-actions { display: flex; align-items: center; gap: 20px; }
.dialog-icon { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: none; }
.dialog-icon:hover { background: rgb(255 255 255 / 7%); }
.art-scroll { display: grid; justify-items: center; align-items: start; overflow: auto; padding: 16px; min-height: 0; overscroll-behavior: contain; }
.art-scroll img { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(96dvh - 155px); cursor: zoom-in; }
.art-scroll.zoomed { display: block; }
.art-scroll.zoomed img { max-width: none; max-height: none; width: max(100%, 1060px); height: auto; margin-inline: auto; cursor: zoom-out; }
.dialog-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line); flex-shrink: 0; }
.dialog-footer > span { font-size: .65rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dialog-footer .text-button { min-height: 28px; }
body.dialog-open { overflow: hidden; }
.noscript-message { max-width: 740px; margin: 24px auto; padding: 20px; line-height: 1.7; color: var(--muted); }
.noscript-message a { color: var(--accent); }

@media (max-width: 640px) {
  :root { --page-width: min(88vw, 440px, max(140px, calc((100svh - 190px) / 1.4))); }
  main { padding-inline: 16px; }
  .book { display: none; }
  .mobile-page { display: block; width: var(--page-width); aspect-ratio: 5 / 7; padding: 0; border: 0; border-radius: 4px; background: #fff; box-shadow: 0 15px 50px rgb(0 0 0 / 45%), 0 0 0 1px rgb(255 255 255 / 15%); overflow: hidden; }
  .mobile-page.reveal { animation: reveal 300ms ease-out; }
  .navigation { width: min(100%, 360px); }
  .dialog-toolbar { padding-inline: 12px; }
  .dialog-toolbar h2 { font-size: .75rem; }
  .dialog-actions { gap: 14px; }
  .dialog-footer { padding-inline: 12px; }
  .dialog-footer .text-button { font-size: .65rem; }
  .art-scroll { padding: 10px; }
}

@keyframes reveal {
  from { opacity: .35; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  :root { --turn-duration: 0ms; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
