:root {
  --bg: #0f172a;
  --panel: rgba(255, 255, 255, 0.9);
  --text: #0f172a;
  --accent: #0f766e;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.25);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e5eef8;
  background:
    radial-gradient(circle at top left, rgba(13, 148, 136, 0.25), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.22), transparent 32%),
    linear-gradient(160deg, #0f172a 0%, #111827 50%, #0b1220 100%);
}

button, input { font: inherit; }
img { -webkit-user-select: none; user-select: none; }

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px;
}

.topbar, .controls, .helper-panel {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #93c5fd;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.1rem);
}

.sub {
  margin: 6px 0 0;
  color: rgba(229, 238, 248, 0.84);
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.left-controls, .jump-controls, .actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.nav-btn, .primary-btn, .secondary-btn, .floating-nav {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.nav-btn:hover, .primary-btn:hover, .secondary-btn:hover, .floating-nav:hover { transform: translateY(-1px); }

.nav-btn, .secondary-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #0d9488);
  color: white;
}

.nav-btn:disabled, .floating-nav:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

.jump-controls label, .status-wrap { font-weight: 600; }

.jump-controls input {
  width: 82px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1rem;
}

.viewer-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.viewer-stage {
  position: relative;
  min-height: calc(100dvh - 220px);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 8px 0 14px;
}

.book-shadow {
  position: absolute;
  width: min(62vw, 760px);
  aspect-ratio: 0.71;
  border-radius: 28px;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.45), rgba(15, 23, 42, 0));
  transform: translateY(38px) scale(1.03);
  filter: blur(14px);
}

.book {
  position: relative;
  width: min(62vw, 760px);
  aspect-ratio: 0.71;
  perspective: 2200px;
  touch-action: pan-y;
  outline: none;
}

.page {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 46px rgba(15, 23, 42, 0.3);
}

.page img, .page-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #fff;
}

.turning-page {
  transform-origin: left center;
  transform-style: preserve-3d;
  pointer-events: none;
  visibility: hidden;
}

.turning-page.active { visibility: visible; }
.turning-page.flip-next { animation: flipNext 650ms cubic-bezier(.2,.75,.15,1) forwards; }
.turning-page.flip-prev { animation: flipPrev 650ms cubic-bezier(.2,.75,.15,1) forwards; transform-origin: right center; }

.page-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: #fff;
}

.page-back { transform: rotateY(180deg); }
.turning-page.flip-prev .page-front { transform: rotateY(180deg); }
.turning-page.flip-prev .page-back { transform: rotateY(0deg); }

.tap-zones {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  z-index: 4;
}

.tap-zone {
  background: transparent;
}

.floating-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.9rem;
  line-height: 1;
  z-index: 6;
  background: rgba(15, 23, 42, 0.36);
  color: #fff;
  backdrop-filter: blur(8px);
}

.floating-prev { left: 10px; }
.floating-next { right: 10px; }

.helper-panel {
  border-radius: 20px;
  padding: 18px 18px 20px;
}

.helper-panel h2 {
  margin: 0 0 12px;
  font-size: 1.08rem;
}

.helper-panel ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.65;
  color: rgba(229, 238, 248, 0.92);
}

@keyframes flipNext {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(-180deg); }
}

@keyframes flipPrev {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(180deg); }
}

body.reading-mode .topbar,
body.reading-mode .controls,
body.reading-mode .helper-panel {
  display: none;
}

body.reading-mode .app-shell {
  max-width: none;
  width: 100%;
  padding: 0;
}

body.reading-mode .viewer-wrap {
  grid-template-columns: 1fr;
}

body.reading-mode .viewer-stage {
  min-height: 100dvh;
  padding: 0;
}

body.reading-mode .book,
body.reading-mode .book-shadow {
  width: min(92vw, calc(100dvh * 0.71 - 12px));
}

body.reading-mode .floating-nav {
  background: rgba(15, 23, 42, 0.5);
}

.viewer-stage:fullscreen,
.viewer-stage:-webkit-full-screen {
  background:
    radial-gradient(circle at top left, rgba(13, 148, 136, 0.2), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.18), transparent 32%),
    linear-gradient(160deg, #0f172a 0%, #111827 50%, #0b1220 100%);
}

.viewer-stage:fullscreen .book,
.viewer-stage:-webkit-full-screen .book,
.viewer-stage:fullscreen .book-shadow,
.viewer-stage:-webkit-full-screen .book-shadow {
  width: min(92vw, calc(100dvh * 0.71 - 12px));
}

.viewer-stage:fullscreen .floating-nav,
.viewer-stage:-webkit-full-screen .floating-nav {
  background: rgba(15, 23, 42, 0.5);
}

@media (max-width: 1080px) {
  .viewer-wrap { grid-template-columns: 1fr; }
  .helper-panel { order: -1; }
  .book, .book-shadow { width: min(84vw, 760px); }
}

@media (max-width: 760px) {
  .app-shell { padding: 12px; }
  .topbar, .controls { padding: 14px; }
  .topbar { gap: 14px; }
  .controls { grid-template-columns: 1fr; }
  .viewer-stage { min-height: calc(100dvh - 250px); }
  .book, .book-shadow { width: min(96vw, 620px); }
  .helper-panel { display: none; }
  .floating-nav {
    width: 42px;
    height: 42px;
    font-size: 1.7rem;
    top: auto;
    bottom: calc(12px + var(--safe-bottom));
    transform: none;
  }
  .floating-prev { left: 12px; }
  .floating-next { right: 12px; }
}
