:root {
  --bg: #f6f1e8;
  --surface: rgba(255,255,255,.86);
  --surface-solid: #fffaf1;
  --ink: #1d1a16;
  --muted: #6e6255;
  --gold: #b9852d;
  --gold-dark: #8b5b16;
  --green: #0d5548;
  --border: rgba(137, 91, 22, .18);
  --shadow: 0 24px 70px rgba(39, 30, 17, .14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(185,133,45,.22), transparent 38rem),
    linear-gradient(135deg, #fbf7ee, var(--bg));
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
code { background: #efe1c7; padding: .15rem .35rem; border-radius: .35rem; }

.hero {
  min-height: 520px;
  padding: 24px clamp(18px, 4vw, 70px) 70px;
  background:
    linear-gradient(115deg, rgba(13,85,72,.94), rgba(18,45,40,.88)),
    radial-gradient(circle at 82% 12%, rgba(255,255,255,.28), transparent 20rem);
  color: #fff8eb;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  inset: auto -6rem -11rem auto;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  border: 70px solid rgba(185,133,45,.24);
}
.topbar, .viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: relative;
  z-index: 2;
}
.brand, .viewer-title {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand img, .viewer-title img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: rgba(255,255,255,.92);
  padding: 7px;
  border-radius: 16px;
}
.brand strong, .viewer-title strong { display: block; font-size: 1.05rem; }
.brand span, .viewer-title span { color: rgba(255,248,235,.72); font-size: .9rem; }
.admin-note {
  border: 1px solid rgba(255,255,255,.28);
  padding: .75rem 1rem;
  border-radius: 999px;
  color: #fff8eb;
}
.hero-content {
  position: relative;
  z-index: 2;
  max-width: 820px;
  margin-top: 96px;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: .16em;
  font-size: .78rem;
}
.hero .eyebrow { color: #ffd68e; }
h1 {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 5.7rem);
  line-height: .94;
  letter-spacing: -.055em;
}
.subtitle {
  max-width: 720px;
  color: rgba(255,248,235,.78);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.7;
}
.hero-actions, .book-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: .9rem 1.2rem;
  font-weight: 800;
  border: 1px solid transparent;
}
.btn.primary { background: linear-gradient(135deg, #d7a64a, #a66c1c); color: #fffaf1; }
.btn.ghost { border-color: var(--border); background: rgba(255,255,255,.5); color: var(--green); }
.hero .btn.ghost { color: #fff8eb; border-color: rgba(255,255,255,.32); background: rgba(255,255,255,.08); }
.btn.small { padding: .65rem .9rem; font-size: .9rem; }

.container { width: min(1180px, calc(100% - 32px)); margin: -42px auto 80px; position: relative; z-index: 3; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 28px;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 260px 140px;
  gap: 18px;
  padding: 20px;
  align-items: end;
}
label { display: block; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #fffaf1;
  border-radius: 16px;
  padding: .95rem 1rem;
  font: inherit;
  color: var(--ink);
  outline: none;
}
.stats {
  background: #0d5548;
  color: #fff8eb;
  border-radius: 20px;
  padding: 14px;
  text-align: center;
}
.stats span { display: block; font-size: 2rem; font-weight: 900; line-height: 1; }
.stats small { color: rgba(255,248,235,.72); }
.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 48px 0 22px;
}
.section-title h2 { margin: 0; font-size: clamp(1.8rem, 3vw, 3rem); letter-spacing: -.04em; }
.section-title > p { max-width: 420px; color: var(--muted); line-height: 1.6; }
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 22px;
}
.book-card {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 16px 44px rgba(39, 30, 17, .1);
  transition: transform .2s ease, box-shadow .2s ease;
}
.book-card:hover { transform: translateY(-5px); box-shadow: 0 24px 70px rgba(39,30,17,.17); }
.cover-wrap {
  display: block;
  aspect-ratio: 3 / 4.2;
  background: linear-gradient(145deg, #efe1c7, #fff6e6);
  overflow: hidden;
}
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-info { padding: 18px; }
.badge {
  display: inline-flex;
  font-size: .78rem;
  font-weight: 900;
  color: var(--gold-dark);
  background: #f3dfb8;
  border-radius: 999px;
  padding: .35rem .65rem;
}
.book-info h3 { margin: 12px 0 6px; font-size: 1.18rem; }
.book-info p { margin: 0 0 16px; color: var(--muted); }
.empty-state {
  text-align: center;
  padding: 44px;
  background: var(--surface-solid);
  border: 1px dashed var(--border);
  border-radius: 24px;
  color: var(--muted);
}
.footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.viewer-page { background: #1b1a17; }
.viewer-header {
  min-height: 76px;
  padding: 12px clamp(12px, 3vw, 34px);
  background: #0d5548;
  color: #fff8eb;
}
.back-link { font-weight: 800; }
.pdf-wrap { height: calc(100vh - 76px); }
.pdf-wrap iframe { width: 100%; height: 100%; border: 0; background: #222; }

.guide { width: min(920px, calc(100% - 32px)); margin: 40px auto; line-height: 1.75; }
.guide-card { background: var(--surface-solid); border: 1px solid var(--border); border-radius: 28px; padding: clamp(22px, 4vw, 42px); box-shadow: var(--shadow); }
.guide h1 { font-size: clamp(2rem, 5vw, 3.8rem); color: var(--green); }
.guide pre { overflow: auto; background: #1d1a16; color: #fff8eb; padding: 18px; border-radius: 18px; }

@media (max-width: 780px) {
  .controls { grid-template-columns: 1fr; }
  .section-title { display: block; }
  .topbar, .viewer-header { align-items: flex-start; }
  .viewer-header { flex-wrap: wrap; }
  .hero-content { margin-top: 64px; }
}

/* ==============================
   FLIPBOOK VIEWER
   ============================== */
.viewer-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.flipbook-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255, 197, 66, 0.18), transparent 32rem),
    linear-gradient(135deg, #07152d 0%, #102f62 52%, #061225 100%);
}

.flipbook-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.flipbook-toolbar {
  margin-bottom: 20px;
  color: #13203a;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.flipbook-toolbar strong,
.flipbook-toolbar span {
  display: block;
}

.flipbook-toolbar span {
  margin-top: 4px;
  color: #68748d;
  font-size: 0.92rem;
}

.book-stage {
  min-height: 72vh;
  border-radius: 28px;
  padding: 34px 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.05)),
    rgba(5, 13, 30, 0.54);
  box-shadow: 0 24px 90px rgba(0,0,0,0.35) inset, 0 18px 50px rgba(0,0,0,0.22);
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.flipbook {
  margin: 0 auto;
}

.flip-page {
  background: #fff;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(10, 28, 55, 0.08);
}

.flip-page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #fff;
  user-select: none;
  pointer-events: none;
}

.loading-box,
.fallback-box {
  margin: 30px auto;
  width: min(520px, 100%);
  border-radius: 22px;
  padding: 28px;
  text-align: center;
  background: rgba(255,255,255,0.95);
  color: #13203a;
  box-shadow: 0 22px 60px rgba(0,0,0,0.22);
}

.loading-box strong,
.loading-box span,
.fallback-box strong,
.fallback-box span {
  display: block;
}

.loading-box span,
.fallback-box span {
  color: #68748d;
  margin: 8px 0 18px;
}

.loader {
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 999px;
  border: 4px solid rgba(16, 47, 98, 0.18);
  border-top-color: #102f62;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
  .viewer-header {
    align-items: stretch;
  }

  .viewer-actions,
  .toolbar-actions,
  .flipbook-toolbar {
    width: 100%;
  }

  .flipbook-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .book-stage {
    min-height: 65vh;
    padding: 22px 8px;
  }
}

/* Optimasi flipbook: halaman dibuat cepat, isi PDF dirender lazy/on-demand */
.flip-page.is-loading {
  background: linear-gradient(135deg, #f8fafc, #e5e7eb);
}
.page-placeholder {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #64748b;
  background: linear-gradient(135deg, #ffffff, #edf2f7);
  border: 1px solid rgba(15, 23, 42, .08);
  box-sizing: border-box;
}
.page-placeholder strong {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(15, 76, 129, .1);
  color: #0f4c81;
  font-size: 18px;
}
.page-placeholder span {
  font-size: 13px;
}
.page-placeholder.error {
  color: #9f1239;
  background: #fff1f2;
}
.flip-page img {
  user-select: none;
  -webkit-user-drag: none;
}
