:root {
  color-scheme: dark;
  --bg: #111314;
  --surface: #171b1f;
  --surface-2: #20252b;
  --text: #f4f6f7;
  --muted: #9ba0a7;
  --accent: #f4a261;
  --border: rgba(255,255,255,.08);
  --shadow: 0 28px 45px rgba(0,0,0,.25);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: Inter, system-ui, sans-serif;
  background: radial-gradient(circle at top, #2f3540 0%, #111314 55%);
  color: var(--text);
}

body {
  padding: 0;
}

.app-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  height: 100vh;
}

main {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.book-panel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  padding: 0;
  margin: 0;
  place-items: center;
}

.book-panel.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(20px);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0.45s ease;
}

.book-panel.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.cover-screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 0;
  background: radial-gradient(circle at top, rgba(255,255,255,.05), transparent 45%);
  box-shadow: none;
  overflow: hidden;
}

.cover-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, rgba(255,255,255,.12), transparent 45%);
  pointer-events: none;
}

.cover-content {
  position: relative;
  z-index: 1;
  width: min(1100px, 80%);
  height: auto;
  text-align: center;
  display: grid;
  align-items: center;
  justify-items: center;
  margin: 0 auto;
}

.cover-image {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease;
}

.cover-screen {
  cursor: pointer;
}

.cover-screen:hover .cover-image,
.cover-screen:focus-visible .cover-image {
  transform: scale(1.01);
}

.cover-content {
  position: relative;
  z-index: 1;
  width: min(100%, 760px);
  text-align: center;
  display: grid;
  gap: 1.25rem;
  align-items: center;
  justify-items: center;
}

.book-frame {
  position: relative;
  width: 90%;
  max-width: 1200px;
  height: 85vh;
  border: none;
  border-radius: 12px;
  background: transparent;
  overflow: hidden;
  margin: 0 auto;
  padding: 0;
  box-shadow: var(--shadow);
}

#book {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent !important;
}

#book, #book * {
  background: transparent !important;
  max-width: 100% !important;
  max-height: 100% !important;
}

/* overlay style (in case JS didn't set inline) */
.book-overlay {
  position: absolute;
  inset: 0;
  background: rgba(17,19,20,1);
  z-index: 9999;
  pointer-events: none;
}

/* Strong overrides for page-flip generated elements to remove white bars */
#book, #book > *,
#book canvas,
#book .page,
#book .st-page,
#book .page__content,
#book .page-content,
#book .page-wrapper,
#book .page-front,
#book .page-back,
#book .book,
#book .page-shadow,
#book .flipbook {
  background: transparent !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

#book::before,
#book::after,
#book .page::before,
#book .page::after {
  background: transparent !important;
  display: none !important;
}

/* Extra aggressive overrides to remove any white bars or rounded edges */
#book,
#book *,
.st-page,
.page,
.pf-page,
.page-flip,
.pageFlip,
.page-wrapper,
.page-front,
.page-back,
.stf-page,
.stf-page__front,
.stf-page__back {
  background: transparent !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
  outline: none !important;
}

/* Mask top/bottom white strips with dark bars matching page background */
#book::before,
#book::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 18px;
  background: linear-gradient(180deg, rgba(17,19,20,1), rgba(47,53,64,1));
  z-index: 9999;
  pointer-events: none;
}
#book::before {
  top: -6px;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}
#book::after {
  bottom: -6px;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

#book > *,
#book canvas,
#book .page,
#book .flipbook {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
}

.page-indicator {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(17,19,20,0.7);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.22);
  pointer-events: none;
}

@media (max-width: 900px) {
  .cover-content {
    width: min(100%, 92%);
  }

  .cover-image {
    max-height: 72vh;
  }

  .book-frame {
    width: 90%;
    max-width: 1000px;
    height: 85vh;
    border-radius: 12px;
    padding: 0;
  }

  .book-panel {
    padding: 0 0.5rem 1rem;
  }
}

@media (max-width: 600px) {
  .cover-image {
    max-height: 58vh;
    border-radius: 14px;
  }

  .book-frame {
    width: 92%;
    max-width: 640px;
    height: 88vh;
    border-radius: 12px;
  }

  .page-indicator {
    bottom: 0.9rem;
    font-size: 0.8rem;
    padding: 0.5rem 0.85rem;
  }
}

/* keep defaults for canvases/images — avoid forcing global scaling that breaks layout */

/* Hint browsers to render images more crisply on mobile devices */
#book img,
#book .page img,
#book .page-content img {
  -webkit-font-smoothing: antialiased;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.thumb-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 0.65rem;
}

.thumb-strip button {
  aspect-ratio: 4 / 5;
  border: 1px solid var(--border);
  border-radius: 14px;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.thumb-strip button[aria-current="true"] {
  border-color: #fbbf24;
  transform: scale(1.02);
}

.thumb-strip button:hover,
.thumb-strip button:focus-visible {
  transform: translateY(-2px);
  outline: none;
}

.fallback {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
  background: rgba(255,255,255,.04);
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.08);
}

.fallback-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.fallback-grid img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

@media (max-width: 860px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .book-frame {
    min-height: 420px;
  }

  .book-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  body {
    padding: 16px;
  }

  .book-frame {
    min-height: 360px;
  }

  .thumb-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
