/* =========================
   BASIC RESET + THEME
   ========================= */

/* Makes sizing easier: padding doesn't increase element width unexpectedly */
* {
  box-sizing: border-box;
}

:root {
  /* Theme colors (easy to tweak) */
  --bg: #0b1020;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --text: #e9ecff;
  --muted: rgba(233, 236, 255, 0.75);

  --accent: #7c5cff;   /* purple */
  --accent2: #2ee59d;  /* green */

  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);

  /* Fancy background gradient */
  background:
    radial-gradient(1200px 600px at 20% 10%, rgba(124, 92, 255, 0.35), transparent 55%),
    radial-gradient(900px 500px at 80% 30%, rgba(46, 229, 157, 0.25), transparent 55%),
    radial-gradient(1000px 700px at 50% 90%, rgba(255, 184, 77, 0.20), transparent 60%),
    var(--bg);

  min-height: 100vh;
}

/* A simple utility class to hide sections */
.hidden {
  display: none !important;
}

.container {
  width: min(1100px, 92vw);
  margin: 22px auto 60px;
}

/* =========================
   TOP BAR
   ========================= */
.topbar {
  width: min(1100px, 92vw);
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 32px;
  filter: drop-shadow(0 10px 22px rgba(0,0,0,0.35));
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}

/* =========================
   BUTTONS
   ========================= */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  color: var(--text);
  background: linear-gradient(135deg, var(--accent), #4b8cff);
  box-shadow: 0 14px 35px rgba(124, 92, 255, 0.25);
  cursor: pointer;
  font-weight: 650;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn.ghost {
  background: var(--panel);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Disabled button style */
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* =========================
   LIBRARY VIEW
   ========================= */
.subtitle {
  color: var(--muted);
  margin: 10px 0 18px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

/* Individual book card */
.book-card {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
  position: relative;
  overflow: hidden;
}

.book-card:hover {
  transform: translateY(-3px);
  background: var(--panel-strong);
}

.book-cover {
  border-radius: 14px;
  height: 140px;
  display: grid;
  place-items: center;
  color: #0b1020;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.25);
}

.book-title {
  margin: 12px 0 2px;
  font-size: 16px;
}

.book-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* A fun little shine effect on hover */
.book-card::after {
  content: "";
  position: absolute;
  top: -30%;
  left: -40%;
  width: 70%;
  height: 160%;
  transform: rotate(20deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.14), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.book-card:hover::after {
  opacity: 1;
}

/* =========================
   READER VIEW
   ========================= */
.reader-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.reader-title {
  margin: 0;
  font-size: 22px;
}

.reader-author {
  margin: 4px 0 0;
  color: var(--muted);
}

.page-counter {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.14);
  padding: 10px 12px;
  border-radius: 14px;
  font-weight: 700;
}

/* The stage centers the flipbook */
.stage {
  display: grid;
  place-items: center;
  margin: 16px 0;
}

/* The flipbook “device” */
.flipbook {
  width: min(900px, 92vw);
  height: min(520px, 60vh);
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;

  /* perspective makes 3D transforms look real */
  perspective: 1400px;
}

/* Each spread is a left page + right page */
.spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

/* Page base */
.page {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

/* Left page background */
.page.left {
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.78));
  color: #101321;
  border-right: 1px solid rgba(0,0,0,0.08);
}

/* Right page background */
.page.right {
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.86));
  color: #101321;
  position: relative;
}

/* Headline inside pages */
.page h3 {
  margin: 0;
  font-size: 20px;
}

.page p {
  margin: 0;
  line-height: 1.55;
  font-size: 16px;
}

/* A little “sticky note” style for fun */
.page .bubble {
  background: rgba(124, 92, 255, 0.14);
  border: 1px solid rgba(124, 92, 255, 0.25);
  padding: 10px 12px;
  border-radius: 14px;
  font-weight: 650;
}

/* =========================
   FLIP ANIMATION
   We animate a "sheet" that flips from right to left
   ========================= */

.sheet {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;

  transform-origin: left center; /* it flips around the middle spine */
  transform-style: preserve-3d;
  pointer-events: none; /* sheet is decorative; user clicks buttons */
}

/* Front face = the current right page content */
.sheet .front,
.sheet .back {
  position: absolute;
  inset: 0;
  border-left: 1px solid rgba(0,0,0,0.08);
  backface-visibility: hidden;
  overflow: hidden;
}

/* Looks like paper */
.sheet .front {
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.86));
  color: #101321;
  padding: 22px;
}

/* Back face = the “back of the page” while flipping */
.sheet .back {
  background: linear-gradient(180deg, rgba(250,250,250,0.88), rgba(240,240,240,0.80));
  transform: rotateY(180deg);
  padding: 22px;
}

/* When we add class "flipping", the sheet rotates */
.sheet.flipping {
  animation: flip 0.65s ease-in-out forwards;
}

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

/* =========================
   CONTROLS
   ========================= */
.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.hint {
  text-align: center;
  color: var(--muted);
  margin: 10px 0 0;
}