:root {
  --red:       #cc0000;
  --red-dark:  #a80000;
  --black:     #111111;
  --white:     #ffffff;
  --offwhite:  #f5f5f5;
  --border:    #e0e0e0;
  --text-mid:  #555555;
  --text-dim:  #999999;
  --page:      #f5eedd;
  --font:      "Montserrat", sans-serif;
}


/* -- Hero strip -- */
.hero-strip {
  background: var(--red);
  display: flex; align-items: center; justify-content: center; gap: 2.5rem;
  padding: 0.55rem 1.5rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em;
  color: rgba(255,255,255,0.9); text-transform: uppercase;
}
.hero-strip .dot { opacity: 0.4; font-size: 0.5rem; }

/* -- Stage -- */
.stage {
  flex: 1;
  background: var(--offwhite);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1rem 0;
}

/* -- Loading / error -- */
.init-msg {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.75rem; color: var(--text-mid); font-size: 0.9rem; font-weight: 600;
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box {
  display: none; color: var(--red-dark); font-size: 0.85rem;
  max-width: 420px; text-align: center;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(204,0,0,0.3);
  border-radius: 4px; background: rgba(204,0,0,0.05);
}

/* -- Book wrap -- */
.book-wrap { display: none; flex-direction: column; align-items: center; }
.book-wrap.active { display: flex; }

.book-surface {
  position: relative;
  /* white card under the book */
  background: var(--white);
  border-radius: 6px;
  padding: 18px 24px 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.07);
  border: 1px solid var(--border);
}

/* subtle drop shadow under book itself */
.book-surface::after {
  content: "";
  position: absolute; left: 10%; right: 10%; bottom: -8px; height: 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.06), transparent);
  filter: blur(3px); pointer-events: none;
}

/* click hint arrows */
.click-hint {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--red); border-radius: 50%;
  color: var(--white); font-size: 0.85rem; font-weight: 700;
  opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 50;
  box-shadow: 0 2px 8px rgba(204,0,0,0.35);
}
.click-hint.left  { left:  -44px; }
.click-hint.right { right: -44px; }
.book-wrap:hover .click-hint { opacity: 1; }

/* -- Book -- */
.book {
  position: relative; display: flex;
  border-radius: 2px 3px 3px 2px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.1);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}

.spine {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 0; bottom: 0; width: 7px; z-index: 30;
  background: linear-gradient(to right, #1a0000 0%, #5a0000 30%, #3a0000 50%, #1a0000 100%);
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
}
.spine::before, .spine::after {
  content: ""; position: absolute; left: 1px; right: 1px;
  height: 1px; background: rgba(255,80,60,0.4);
}
.spine::before { top: 12%; } .spine::after { bottom: 12%; }

/* -- Pages -- */
.page {
  position: relative; overflow: hidden;
  background: var(--page); flex-shrink: 0;
}
.page canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
#pageLeft  { border-radius: 2px 0 0 2px; }
#pageRight { border-radius: 0 2px 2px 0; }
#pageLeft::after {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 32px;
  background: linear-gradient(to right, transparent, rgba(0,0,0,0.09));
  pointer-events: none; z-index: 3;
}
#pageRight::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 32px;
  background: linear-gradient(to left, transparent, rgba(0,0,0,0.09));
  pointer-events: none; z-index: 3;
}
.page-stack { position: absolute; top: 1px; bottom: 1px; width: 4px; z-index: 2; }
.stack-right {
  right: -4px;
  background: repeating-linear-gradient(to right, #ddd5bc 0px,#c8bfa8 1px,#e8dfc8 1px,#ddd5bc 2px);
  border-radius: 0 2px 2px 0; box-shadow: 2px 0 4px rgba(0,0,0,0.18);
}
.stack-left {
  left: -4px;
  background: repeating-linear-gradient(to left, #ddd5bc 0px,#c8bfa8 1px,#e8dfc8 1px,#ddd5bc 2px);
  border-radius: 2px 0 0 2px; box-shadow: -2px 0 4px rgba(0,0,0,0.18);
}

/* -- Flip container -- */
#flipContainer {
  position: absolute; top: 0; height: 100%;
  display: none; transform-style: preserve-3d; z-index: 20;
}
.flip-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden; background: var(--page);
}
.flip-face canvas { display: block; width: 100%; height: 100%; position: absolute; inset: 0; }
#flipBackFace { transform: rotateY(180deg); }

.loading-overlay {
  display: none; position: absolute; inset: 0;
  background: rgba(255,255,255,0.7);
  align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.loading-overlay.visible { display: flex; }

/* -- Navigation -- */
.nav-flip {
  display: none; align-items: center; justify-content: center;
  gap: 1rem; padding: 1.2rem 1rem 0.5rem;
}
.nav-flip.visible { display: flex; }

.nav-flip .nav-btn {
  background: var(--red); border: none; color: var(--white);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.18s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(204,0,0,0.3);
}
.nav-flip .nav-btn:hover:not(:disabled) { background: var(--red-dark); }
.nav-flip .nav-btn:active:not(:disabled) { transform: scale(0.92); }
.nav-flip .nav-btn:disabled { opacity: 0.2; cursor: default; pointer-events: none; box-shadow: none; }

.page-info {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em;
  color: var(--text-dim); text-transform: uppercase; min-width: 110px; text-align: center;
}

/* -- Hint bar -- */
.hint-bar {
  display: none; align-items: center; justify-content: center; gap: 1.5rem;
  padding: 0 1rem 1.5rem;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim);
}
.hint-bar.on { display: flex; }
.hint-bar span { display: flex; align-items: center; gap: 0.35rem; }
.hint-bar .icon { font-size: 0.8rem; }

/* -- Footer -- */
footer {
  background: var(--black); color: rgba(255,255,255,0.45);
  text-align: center; padding: 0.75rem 1rem;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase;
}
footer strong { color: var(--red); }

/* -- Mobile -- */
@media (max-width: 660px) {
  .spine, .click-hint, .stack-left, .keyboard-hint { display: none; }
  #pageLeft { display: none !important; }
  #pageRight { border-radius: 3px; }
  .book { border-radius: 3px; }
  .book-surface { padding: 12px; }
  .topbar { display: none; }
  header { padding: 0.6rem 1rem; }
}