/* ==========================================================================
   Katalog Buku — Contoh Kandungan
   Vanilla CSS. No frameworks.
   ========================================================================== */

:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --line: #e8e4dc;
  --ink: #16233d;
  --ink-soft: #6d6961;
  --accent: #d81e5b;
  --radius: 20px;
  --font-display: "Nunito", system-ui, sans-serif;
  --font-body: "Nunito Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: #1c1b19;
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body.is-locked { overflow: hidden; }

img { max-width: 100%; }

button { font-family: inherit; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* --------------------------------------------------------- Page shell --- */

.page { min-height: 100vh; padding: 0 20px 96px; }

.site-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 72px 0 44px;
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid #e4e0d8;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  max-width: 100%;
  margin: 0;
}
@media (max-width: 420px) {
  .eyebrow { font-size: 10px; letter-spacing: .1em; padding: 6px 12px; }
}
.eyebrow::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.site-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(32px, 5.2vw, 56px);
  line-height: 1.08;
  letter-spacing: -.02em;
  margin: 22px 0 0;
  color: var(--ink);
  text-wrap: balance;
}

.site-subtitle {
  margin: 16px auto 0;
  max-width: 620px;
  font-size: clamp(15px, 1.7vw, 19px);
  line-height: 1.6;
  color: #5f5b53;
  text-wrap: pretty;
}

/* --------------------------------------------------------------- Grid --- */
/* Auto-fill handles every breakpoint: 4-up on desktop, 3-up on tablet,
   2-up on phones. The media query below forces 1-up on very small screens. */

.book-grid {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(45%, 230px), 1fr));
  gap: 26px;
}

@media (max-width: 720px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}
@media (max-width: 380px) {
  .book-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------- Card --- */

.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(28, 27, 25, .05);
  transition: box-shadow .3s ease, transform .3s ease;
}

.book-card:hover,
.book-card:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px rgba(22, 35, 61, .16);
}

.book-cover {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #f7f5f1;
  cursor: pointer;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  position: relative;
}

/* Fallback text sits behind the cover image; it shows if the image fails. */
.book-cover::after {
  content: "kulit buku";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: .08em;
  color: #b5aea3;
}

.book-cover img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform .5s cubic-bezier(.2, .7, .2, 1);
}
.book-cover img.is-broken { visibility: hidden; }

.book-card:hover .book-cover img,
.book-card:focus-within .book-cover img { transform: scale(1.06); }

.level-badge {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(22, 35, 61, .86);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.book-body {
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.book-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -.01em;
  margin: 0;
  color: var(--ink);
  text-wrap: balance;
}

.book-desc {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  text-wrap: pretty;
  flex: 1;
}

.book-btn {
  margin-top: 6px;
  width: 100%;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px solid #d9d4ca;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .22s ease, color .22s ease, border-color .22s ease;
}

.book-card:hover .book-btn,
.book-card:focus-within .book-btn,
.book-btn:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ----------------------------------------------------------- Lightbox --- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(14, 17, 24, .9);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
  animation: lb-fade .22s ease both;
}
.lightbox[hidden] { display: none; }

@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-spin { to { transform: rotate(360deg); } }

.lb-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  flex: 0 0 auto;
}

.lb-meta { min-width: 0; flex: 1; }

.lb-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(15px, 2.4vw, 21px);
  margin: 0;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-counter { margin: 2px 0 0; font-size: 12.5px; color: rgba(255, 255, 255, .6); }

.lb-tools { display: flex; align-items: center; gap: 8px; }

.lb-tool {
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease;
}
.lb-tool:hover { background: rgba(255, 255, 255, .18); }
.lb-tool.is-zoom-label { font-size: 13px; }

.lb-close { margin-left: 4px; background: var(--accent); border-color: var(--accent); }
.lb-close:hover { background: #b9174c; }

.lb-view {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 14px 8px;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(20, 24, 33, .75);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease;
}
.lb-nav:hover { background: rgba(20, 24, 33, .95); }
.lb-nav[hidden] { display: none; }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }

.lb-stage {
  position: relative;
  height: 100%;
  max-width: min(100%, 1000px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.lb-stage.is-zoomed { cursor: grab; }
.lb-stage.is-panning { cursor: grabbing; }

.lb-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 10px;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  transition: opacity .2s ease;
}
.lb-image.is-hidden { opacity: 0; }

.lb-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  color: rgba(255, 255, 255, .72);
  font-size: 13px;
}
.lb-spinner[hidden] { display: none; }
.lb-spinner::before {
  content: "";
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .22);
  border-top-color: #fff;
  animation: lb-spin .8s linear infinite;
}

.lb-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lb-error[hidden] { display: none; }
.lb-error > div {
  max-width: 340px;
  text-align: center;
  padding: 28px 24px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .07);
  border: 1px dashed rgba(255, 255, 255, .3);
}
.lb-error strong {
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-display);
  font-size: 16px;
  color: #fff;
}
.lb-error span { font-size: 13.5px; line-height: 1.55; color: rgba(255, 255, 255, .66); }

.lb-thumbs-wrap {
  flex: 0 0 auto;
  padding: 10px 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

.lb-thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px;
  justify-content: safe center;
}

.lb-thumb {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, .25);
  opacity: .6;
  transition: border-color .2s ease, opacity .2s ease;
}
.lb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lb-thumb:hover { opacity: .85; }
.lb-thumb[aria-current="true"] { border-color: var(--accent); opacity: 1; }

@media (max-width: 520px) {
  .lb-nav { width: 46px; height: 46px; }
  .lb-thumb { width: 54px; height: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
