:root {
  --black: #11110f;
  --ink: #23221f;
  --cream: #f2ebdd;
  --paper: #fffdf8;
  --muted: #a9a397;
  --line: rgba(242, 235, 221, .22);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 12%, #37352f 0, #1d1c19 36%, var(--black) 76%);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

button, a, input { font: inherit; }

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(17, 17, 15, .84);
  backdrop-filter: blur(12px);
}

.brand h1 { margin: 2px 0 0; font-size: clamp(1.4rem, 3vw, 2.2rem); letter-spacing: .02em; }
.eyebrow { color: var(--muted); font-size: .72rem; letter-spacing: .18em; }
.top-actions { display: flex; align-items: center; gap: 10px; }

button, .download-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--cream);
  background: #24231f;
  cursor: pointer;
  transition: background .18s ease, transform .18s ease, border-color .18s ease;
}

button:hover, .download-button:hover { background: #34322c; border-color: rgba(242, 235, 221, .5); }
button:active, .download-button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #d4b879; outline-offset: 2px; }

.download-button { display: inline-flex; align-items: center; padding: 0 16px; text-decoration: none; font-weight: 700; }
.icon-button { width: 44px; font-size: 1.35rem; }

main { padding: clamp(14px, 2.2vw, 28px) 14px 28px; }
.reader { position: relative; width: min(100%, 1180px); height: min(71vh, 790px); margin: 0 auto; display: grid; place-items: center; }
.book { filter: drop-shadow(0 24px 38px rgba(0, 0, 0, .55)); transition: transform .18s ease; transform-origin: center; }

.page { background: var(--paper); overflow: hidden; }
.page canvas { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--paper); }
.page-loading { width: 100%; height: 100%; display: grid; place-items: center; color: #69665f; background: var(--paper); font-size: .9rem; }

.page-arrow {
  position: absolute;
  z-index: 10;
  top: 50%;
  width: 52px;
  height: 70px;
  transform: translateY(-50%);
  border: 0;
  background: rgba(17, 17, 15, .72);
  font-size: 3rem;
  line-height: 1;
}
.page-arrow:active { transform: translateY(-49%); }
.page-arrow-left { left: max(0px, calc(50% - 600px)); }
.page-arrow-right { right: max(0px, calc(50% - 600px)); }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 18px auto 0;
}
.controls button { padding: 0 14px; }
.page-status { display: flex; align-items: center; gap: 7px; padding: 0 8px; color: #d8d2c6; }
.page-status input { width: 64px; height: 42px; padding: 0 8px; text-align: center; color: var(--ink); background: var(--cream); border: 0; border-radius: 3px; }
.zoom-value { min-width: 50px; text-align: center; color: var(--muted); }
.hint { margin: 12px auto 0; text-align: center; color: var(--muted); font-size: .82rem; }

.loading { min-height: 68vh; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.spinner { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--cream); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error { max-width: 560px; margin: 40px auto; padding: 28px; text-align: center; color: var(--cream); background: #2d1c1c; border: 1px solid #825d5d; }

@media (max-width: 720px) {
  .topbar { min-height: 70px; padding: 10px 14px; }
  .eyebrow { display: none; }
  .download-button { padding: 0 11px; font-size: .85rem; }
  .reader { height: 66vh; }
  .page-arrow { width: 42px; height: 58px; font-size: 2.4rem; }
  .page-arrow-left { left: 0; }
  .page-arrow-right { right: 0; }
  .controls button { padding: 0 10px; }
  #backBtn, #forwardBtn { display: none; }
}

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

/* Ensure HTML hidden state wins over component display rules. */
[hidden] { display: none !important; }

/* V2: the flipbook uses pre-rendered page images for reliable display on Netlify. */
.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--paper);
  user-select: none;
  -webkit-user-drag: none;
}
