:root {
  --bg: #0c1a2c;
  --bar: #091422;
  --border: #1e334d;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --gold: #d4a353;
  --gold-text: #111827;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(circle at 50% 45%, #152c4a 0%, var(--bg) 72%);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 54px;
  padding: 0 18px;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--gold);
  flex-shrink: 0;
}
.brand-name {
  font-size: 13px;
  letter-spacing: 0.03em;
  color: #f8fafc;
  white-space: nowrap;
}
.brand-sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

select, button, input[type="number"] {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #132438;
  color: #f8fafc;
  padding: 6px 10px;
  font-size: 13px;
}
select { max-width: 290px; cursor: pointer; }
button { cursor: pointer; }
.btn-gold {
  background: var(--gold);
  color: var(--gold-text);
  border-color: var(--gold);
  font-weight: 700;
}
.btn-icon { width: 34px; text-align: center; padding: 6px 0; }

#book-viewport {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 56px;
  min-height: 0;
}

.side-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 58px;
  border-radius: 8px;
  background: rgba(15, 29, 48, 0.88);
  border: 1px solid var(--border);
  color: #e2e8f0;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.side-nav:hover:not(:disabled) {
  background: #1b3352;
  border-color: var(--gold);
  transform: translateY(-50%) scale(1.05);
}
.side-nav:disabled { opacity: 0.28; cursor: not-allowed; }
.side-prev { left: 12px; }
.side-next { right: 12px; }

.book-scene {
  perspective: 2600px;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 100%;
  max-width: 100%;
}

.book-spread {
  position: relative;
  display: flex;
  background: #ffffff;
  border-radius: 4px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  transform-style: preserve-3d;
  user-select: none;
}

.page-slot {
  position: relative;
  background: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-slot img {
  display: block;
  height: calc(100vh - 128px);
  width: auto;
  max-width: 44.5vw;
  object-fit: contain;
  cursor: zoom-in;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.book-spread.single-mode .page-slot img {
  max-width: 86vw;
}

.spine-shadow-left {
  position: absolute;
  top: 0; right: 0; bottom: 0; width: 32px;
  background: linear-gradient(to left, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0.05) 45%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}
.spine-shadow-right {
  position: absolute;
  top: 0; left: 0; bottom: 0; width: 32px;
  background: linear-gradient(to right, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.04) 45%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}

/* Hiệu ứng góc trang uốn cong tự nhiên ở góc dưới phải */
.corner-curl {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 48px;
  height: 48px;
  cursor: pointer;
  z-index: 8;
  overflow: hidden;
  transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1), height 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.curl-flap {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    transparent 46%,
    rgba(15, 23, 42, 0.18) 49%,
    #cbd5e1 52%,
    #ffffff 66%,
    #e2e8f0 88%,
    #94a3b8 100%
  );
  border-top-left-radius: 8px;
  box-shadow: -4px -4px 12px rgba(0, 0, 0, 0.28);
}
.right-slot:hover .corner-curl,
.corner-curl:hover {
  width: 82px;
  height: 82px;
}

/* Lớp phủ bóng đổ động trên mặt sách khi trang đang lật */
.underlay-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background: rgba(0, 0, 0, 0);
}

/* Lá sách 3D mượt 60fps bằng Web Animations API */
.flip-leaf {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  z-index: 14;
  pointer-events: none;
  will-change: transform;
}
.flip-leaf.single-leaf {
  width: 100%;
  left: 0;
  transform-origin: left center;
}

.leaf-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.leaf-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.leaf-back {
  transform: rotateY(180deg);
}

.leaf-gradient-front {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(0,0,0,0.14) 0%, rgba(0,0,0,0) 20%, rgba(0,0,0,0.06) 100%);
  pointer-events: none;
}
.leaf-gradient-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(to left, rgba(0,0,0,0.14) 0%, rgba(0,0,0,0) 20%, rgba(0,0,0,0.06) 100%);
  pointer-events: none;
}

.bottombar {
  height: 50px;
  padding: 0 20px;
  background: var(--bar);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

#page-slider {
  flex: 1;
  accent-color: var(--gold);
  cursor: pointer;
}

.page-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
#page-input {
  width: 54px;
  text-align: center;
  padding: 4px 6px;
}

.zoom-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 11, 20, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px;
}
.zoom-modal[hidden] { display: none; }

.zoom-toolbar {
  width: 100%;
  max-width: 1280px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 10px;
  flex-shrink: 0;
}
.zoom-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.zoom-scroll {
  flex: 1;
  width: 100%;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
#zoom-img {
  width: 1120px;
  max-width: none;
  height: auto;
  border-radius: 6px;
  background: #fff;
  transition: width 0.18s ease;
}

@media (max-width: 860px) {
  .brand-sub { display: none; }
  #book-viewport { padding: 8px 42px; }
  .side-nav { width: 32px; height: 46px; font-size: 22px; }
  .side-prev { left: 6px; }
  .side-next { right: 6px; }
  select { max-width: 155px; }
}
