:root {
  --bg: #07080b;
  --text: #f7f2e8;
  --muted: rgba(247, 242, 232, .68);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

.shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 14px;
  padding: 20px 16px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 48% 48%, rgba(142, 22, 32, .34), transparent 38%),
    radial-gradient(circle at 54% 35%, rgba(0, 124, 97, .25), transparent 42%),
    linear-gradient(180deg, #050506, #0b0a0d 45%, #030304);
}

/* Three-column flex: arrow | book | arrow */
.book-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 0;
}

.ambient {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(95vw, 1100px);
  height: min(85vh, 850px);
  border-radius: 26px;
  background: radial-gradient(circle, rgba(255, 255, 255, .11), transparent 68%);
  filter: blur(26px);
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}

/* Cap by height first; width follows from aspect ratio so book always fits */
.book {
  position: relative;
  z-index: 1;
  height: min(85vh, 800px);
  width: auto;
  filter: drop-shadow(0 28px 44px rgba(0, 0, 0, .68));
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.page {
  background: #111;
  overflow: hidden;
}

.page picture,
.page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

/* StPageFlip's rendered page items */
.stf__item {
  background: #111;
}
.stf__item.--soft {
  border-radius: 0 6px 6px 0;
}
.stf__item.--hard {
  background: #0a0a0a;
  border-radius: 4px 10px 10px 4px;
}
.stf__item.--left.--hard {
  border-radius: 10px 4px 4px 10px;
}

/* Nav arrows — inline siblings of the book */
.nav {
  flex-shrink: 0;
  width: 48px;
  height: 74px;
  border: 0;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, .1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 56px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
  z-index: 10;
}

.nav:hover { background: rgba(255, 255, 255, .18); transform: scale(1.04); }
.nav:disabled { opacity: .22; cursor: not-allowed; }

.controls {
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
}

.controls button {
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 9px 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
  font-size: 13px;
  letter-spacing: .01em;
  font-family: inherit;
}

.controls button:hover { background: rgba(255, 255, 255, .15); }
.controls button:disabled { opacity: .35; cursor: not-allowed; }

.page-count {
  min-width: 72px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  /* Mobile: full-screen book experience. The bottom controls toolbar is
     hidden entirely; the book fills the available viewport. Arrows become
     small floating overlays on top of the book, not inline siblings. */
  .shell {
    padding: 0;
    grid-template-rows: 1fr;  /* No room for the controls row */
    gap: 0;
  }
  .controls {
    display: none;
  }
  .book-wrap {
    position: relative;
    padding: 0;
    gap: 0;
  }
  /* The book sizes itself to fill the available space, leaving small breathing
     room for the safe-area insets. */
  .book {
    height: 100vh;
    height: 100svh;
    max-height: 100vh;
    max-height: 100svh;
    width: auto;
    /* Keep the drop-shadow for depth even when there's not much background */
    filter: drop-shadow(0 14px 26px rgba(0, 0, 0, .55));
  }
  /* Arrows: smaller, floating overlays positioned absolutely against the book-wrap,
     not flex siblings that take up width. Pulled to the left/right edges of the
     viewport, vertically centered, semi-transparent. */
  .nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 60px;
    font-size: 40px;
    background: rgba(255, 255, 255, .12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
  }
  .nav:hover { transform: translateY(-50%) scale(1.04); }
  .nav-left  { left: 6px; }
  .nav-right { right: 6px; }
}

@media (max-height: 700px) and (min-width: 701px) {
  /* Desktop short-screen (e.g. landscape laptop with the dev tools open):
     just shrink the book vertically. Keep the controls. */
  .book { height: min(80vh, 600px); }
}
