:root {
  --orange: #f47a00;
  --charcoal: #202526;
  --panel: #2d3233;
  --muted: #cfd2cf;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #151819; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: #f4f4ef;
  font-family: Arial, Tahoma, sans-serif;
  background:
    radial-gradient(circle at 50% 18%, #687071 0, #34393a 34%, #202425 68%, #151819 100%);
}

.app { width: min(1540px, 100%); margin: auto; padding: 18px 22px 28px; }
header {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1210px;
  margin: 0 auto 15px;
}
.brand { font: 700 38px/1 Arial; color: var(--orange); letter-spacing: 5px; }
.heading { flex: 1; }
h1 { margin: 0 0 5px; font-size: 18px; }
.heading p { margin: 0; color: var(--muted); font-size: 12px; }
.download {
  padding: 9px 16px;
  border: 1px solid #f47a0099;
  border-radius: 22px;
  color: #fff;
  font-size: 12px;
  text-decoration: none;
  transition: .22s ease;
}
.download:hover { background: var(--orange); color: var(--charcoal); }

.stage { display: grid; place-items: center; min-height: 0; perspective: 2600px; }
.book-shell {
  position: relative;
  width: min(1180px, 94vw);
  aspect-ratio: 1.414 / 1;
  filter: drop-shadow(0 28px 28px #0009);
}
#book { width: 100%; height: 100%; }
#book canvas { border-radius: 4px; }
.mobile-turn-overlay {
  position: absolute;
  z-index: 16;
  inset: 0;
  overflow: hidden;
  border-radius: 4px;
  pointer-events: none;
}
.mobile-turn-book { width: 100%; height: 100%; }
.mobile-turn-book canvas { border-radius: 4px; }
.mobile-turn-overlay.turn-ltr .mobile-turn-book { transform: scaleX(-1) !important; }
.book-fallback { display: block; width: auto; max-width: 100%; height: 100%; margin: 0 auto; object-fit: contain; border-radius: 4px; }

/* The engine owns the curl. These zones only make the full outer edge of the
   current sheet clickable, matching commercial digital-catalog behaviour. */
.edge {
  position: absolute;
  z-index: 20;
  bottom: 0;
  width: 72px;
  height: 72px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.edge[hidden] { display: none; }
.edge-next { right: 0; }
.edge-prev { left: 0; }
html[dir="rtl"] .edge-next { right: auto; left: 0; }
html[dir="rtl"] .edge-prev { left: auto; right: 0; }
.edge::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 62px;
  height: 62px;
  opacity: .72;
  transition: width .22s ease, height .22s ease, opacity .22s ease;
  background: linear-gradient(135deg, transparent 0 49%, #f47a00b8 50% 52%, #202526e8 53% 100%);
  filter: drop-shadow(0 5px 6px #0008);
}
.edge:hover::after { width: 82px; height: 82px; opacity: 1; }
.edge-next::after { right: 0; clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.edge-prev::after { left: 0; transform: scaleX(-1); clip-path: polygon(100% 0, 100% 100%, 0 100%); }
html[dir="rtl"] .edge-next::after { right: auto; left: 0; transform: scaleX(-1); }
html[dir="rtl"] .edge-prev::after { left: auto; right: 0; transform: none; }
.edge span {
  position: absolute;
  bottom: 13px;
  z-index: 2;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid #f47a00cc;
  border-radius: 50%;
  background: #202526e8;
  color: #fff;
  font-size: 17px;
  line-height: 1;
  box-shadow: 0 5px 12px #0007;
}
.edge-next span { right: 11px; }
.edge-prev span { left: 11px; }
html[dir="rtl"] .edge-next span { right: auto; left: 11px; }
html[dir="rtl"] .edge-prev span { left: auto; right: 11px; }

nav {
  direction: ltr;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin-top: 15px;
}
nav button {
  padding: 10px 18px;
  border: 1px solid #f47a0088;
  border-radius: 24px;
  background: var(--panel);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: .2s;
}
nav button:hover:not(:disabled) { background: var(--orange); color: #1d2021; }
button:disabled { opacity: .28; cursor: default; }
#status { min-width: 145px; text-align: center; color: #d6d8d5; font-size: 13px; }
.thumbs {
  display: flex;
  direction: ltr;
  justify-content: center;
  gap: 7px;
  max-width: 900px;
  margin: 13px auto 0;
  padding: 4px;
  overflow-x: auto;
}
.thumbs button {
  width: 48px;
  height: 68px;
  flex: 0 0 48px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #f47a0088;
  border-radius: 4px;
  background: var(--panel);
  opacity: .53;
  cursor: pointer;
}
.thumbs button.active { opacity: 1; border-color: var(--orange); box-shadow: 0 0 0 1px var(--orange); }
.thumbs img { display: block; width: 100%; height: 100%; object-fit: cover; }
body[data-flip-state="flipping"] .edge { pointer-events: none; }

@media (max-width: 760px) {
  .app { padding: 10px 7px 18px; }
  header { gap: 10px; flex-wrap: wrap; }
  .brand { font-size: 28px; }
  .heading { min-width: 210px; }
  h1 { font-size: 14px; }
  .download { padding: 7px 11px; font-size: 11px; }
  .book-shell { width: min(96vw, 520px); aspect-ratio: 1488 / 2105; }
  .edge { width: 62px; height: 62px; }
  .edge::after { width: 52px; height: 52px; }
  .edge:hover::after { width: 62px; height: 62px; }
  .edge span { bottom: 9px; width: 25px; height: 25px; font-size: 15px; }
  .edge-next span { right: 8px; }
  .edge-prev span { left: 8px; }
  html[dir="rtl"] .edge-next span { left: 8px; }
  html[dir="rtl"] .edge-prev span { right: 8px; }
  nav { gap: 8px; }
  nav button { padding: 9px 12px; }
  #status { min-width: 100px; }
  .thumbs { justify-content: flex-start; }
  .thumbs button { width: 42px; height: 60px; flex-basis: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .edge::after { transition: none; }
}
