/* ─────────────────────────────────────────────────────
   Reset
───────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ─────────────────────────────────────────────────────
   Tokens
───────────────────────────────────────────────────── */
:root {
  --bg:          #0d0d10;
  --surface:     #16171c;
  --border:      rgba(255,255,255,.07);
  --accent:      #c8956c;
  --accent-dim:  rgba(200,149,108,.15);
  --text:        #ececec;
  --muted:       rgba(255,255,255,.38);
  --topbar-h:    48px;
  --controls-h:  60px;
  --radius:      8px;
  --ease-flip:   cubic-bezier(.45,.05,.35,1);
}

/* ─────────────────────────────────────────────────────
   Base
───────────────────────────────────────────────────── */
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(200,149,108,.12) 0%, transparent 70%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─────────────────────────────────────────────────────
   Loading overlay
───────────────────────────────────────────────────── */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 900;
  transition: opacity .45s ease, visibility .45s ease;
}
.loader.out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 260px;
}

.loader-logo {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .25em;
  color: var(--accent);
  opacity: .8;
}

/* Spinner */
.spinner {
  position: relative;
  width: 52px;
  height: 52px;
}
.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.06);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-text {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
  transition: color .3s;
}

/* Progress bar */
.progress-track {
  width: 100%;
  height: 2px;
  background: rgba(255,255,255,.06);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, #e8c09a 100%);
  border-radius: 2px;
  transition: width .22s ease;
}

.error-msg {
  font-size: 12px;
  color: #e07070;
  text-align: center;
  display: none;
}

/* ─────────────────────────────────────────────────────
   App shell
───────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: opacity .4s ease;
}
.app.hidden { opacity: 0; pointer-events: none; }
.app.visible { opacity: 1; }

/* ─────────────────────────────────────────────────────
   Top bar
───────────────────────────────────────────────────── */
.topbar {
  flex-shrink: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(13,13,16,.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .22em;
  color: var(--accent);
}

.page-num {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .04em;
}

/* ─────────────────────────────────────────────────────
   Stage (3-D viewport)
───────────────────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2800px;
  overflow: hidden;
  /* leave room for top/bottom bars */
  padding: 12px 24px;
}

/* ─────────────────────────────────────────────────────
   Book container – PageFlip manages its own children
───────────────────────────────────────────────────── */
.book {
  /* PageFlip sets explicit width/height inline */
  position: relative;
}

/* ─────────────────────────────────────────────────────
   Page elements (PageFlip reads these)
───────────────────────────────────────────────────── */
.page {
  background: #fff;
  overflow: hidden;
  /* PageFlip sets inline size */
}

.page canvas {
  display: block;
  /* CSS size is set via JS = PAGE_W × PAGE_H
     Canvas pixel size = CSS × RETINA (sharp on HiDPI) */
  width: 100%;
  height: 100%;
}

/* ─────────────────────────────────────────────────────
   Controls bar
───────────────────────────────────────────────────── */
.controls {
  flex-shrink: 0;
  height: var(--controls-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(13,13,16,.85);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.11);
  color: var(--text);
  border-radius: 50px;
  cursor: pointer;
  transition: background .18s, transform .12s, opacity .18s;
  font-size: 13px;
  width: 36px;
  height: 36px;
}
/* Large arrow buttons */
.ctrl-btn.arrow {
  width: 52px;
  height: 42px;
  font-size: 30px;
  line-height: 1;
}

.ctrl-btn:hover:not(:disabled) {
  background: rgba(255,255,255,.14);
}
.ctrl-btn:active:not(:disabled) {
  transform: scale(.92);
}
.ctrl-btn:disabled {
  opacity: .18;
  cursor: default;
}

/* ─────────────────────────────────────────────────────
   Responsive – mobile
───────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .stage { padding: 8px; }

  .ctrl-btn:not(.arrow) { display: none; } /* hide ⏮ ⏭ on mobile */

  .controls { gap: 20px; }
}

@media (max-width: 400px) {
  .ctrl-btn.arrow { width: 44px; height: 38px; font-size: 26px; }
}
