@font-face {
  font-family: "Source Sans Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/source-sans-pro-400.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../assets/fonts/source-sans-pro-600.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../assets/fonts/source-sans-pro-700.woff2") format("woff2");
}

:root {
  --wine: #900028;
  --wine-lift: #b21440;
  --wine-deep: #5c001a;
  --ink: #2a2422;
  --muted: #8a827e;
  --paper: #ffffff;
  --line: rgba(20, 12, 14, .12);
  --glass: rgba(255, 255, 255, .72);
  --shadow-book: 0 30px 70px -28px rgba(60, 20, 30, .45), 0 10px 30px -14px rgba(0, 0, 0, .22);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --slide: .55s cubic-bezier(.22, 1, .36, 1);
  --ui: "Source Sans Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #ffffff;
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.app {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, #ffffff, #ffffff 40%, #f4f0ee 100%);
}

/* ---------- Top bar ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 3vw, 34px);
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}

.brand { display: flex; align-items: center; gap: 16px; }
.brand__logo { height: 40px; width: auto; display: block; }
.brand__divider { width: 1px; height: 30px; background: var(--line); }
.brand__sub {
  font-size: 11px;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.topbar__actions { display: flex; gap: 10px; }

.iconbtn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .7);
  color: var(--ink);
  cursor: pointer;
  transition: background .25s var(--ease), border-color .25s var(--ease), color .25s var(--ease), transform .15s var(--ease);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.iconbtn:hover { background: var(--wine); border-color: var(--wine); color: #fff; }
.iconbtn:active { transform: scale(.94); }
.iconbtn .ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic-fs-close { display: none; }
:fullscreen .ic-fs-open, .is-fs .ic-fs-open { display: none; }
:fullscreen .ic-fs-close, .is-fs .ic-fs-close { display: block; }

/* ---------- Stage ---------- */
.stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 74px clamp(10px, 4vw, 64px) 96px;
}

.book-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transition: transform .45s var(--ease);
  transform-origin: center;
}
.book-wrap.is-zoomed { cursor: grab; }
.book-wrap.is-zoomed:active { cursor: grabbing; }

.flipbook {
  width: 100%;
  height: 100%;
  filter: drop-shadow(var(--shadow-book));
  will-change: transform;
}
.flipbook .page { background: var(--paper); overflow: hidden; }
.flipbook .page img {
  width: 100%; height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.flipbook .page::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .04);
}

/* click zones */
.edge {
  position: absolute;
  top: 0; bottom: 0;
  width: clamp(48px, 8vw, 130px);
  border: 0; background: transparent;
  cursor: pointer; z-index: 20;
  opacity: 0;
  transition: opacity .3s var(--ease);
}
.edge--prev { left: 0; }
.edge--next { right: 0; }
.stage:hover .edge { opacity: 1; }
.edge::before {
  content: "";
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, .3);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background .2s var(--ease), border-color .2s var(--ease);
}
.edge--prev::before { left: 18px; }
.edge--next::before { right: 18px; }
.edge::after {
  content: "";
  position: absolute; top: 50%;
  width: 11px; height: 11px;
  border-top: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  transition: border-color .2s var(--ease);
}
.edge--prev::after { left: 40px; transform: translateY(-50%) rotate(-135deg); }
.edge--next::after { right: 40px; transform: translateY(-50%) rotate(45deg); }
.edge:hover::before { background: var(--wine); border-color: var(--wine); }
.edge:hover::after { border-color: #fff; }
.edge[disabled] { display: none; }

/* ---------- Controls ---------- */
.controls {
  position: absolute;
  left: 50%;
  bottom: clamp(16px, 3.4vh, 30px);
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 24px 50px -22px rgba(40, 15, 25, .35), 0 4px 14px -8px rgba(0, 0, 0, .2);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}

.ctl {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease), transform .12s var(--ease);
}
.ctl svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ctl:hover { background: rgba(144, 0, 40, .1); color: var(--wine); }
.ctl:active { transform: scale(.9); }
.ctl:disabled { opacity: .26; pointer-events: none; }
.ctl--wide { width: auto; padding: 0 14px; gap: 8px; }
.ctl.is-active { background: var(--wine); color: #fff; }

.ctl__divider { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }

.pager {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  min-width: clamp(120px, 24vw, 240px);
}

.pager__label {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pager__label #page-now { color: var(--wine); font-weight: 700; }
.pager__sep { margin: 0 5px; color: var(--line); }

/* ---------- Animated slider ---------- */
.track {
  position: relative;
  width: 100%;
  height: 15px;
  display: flex;
  align-items: center;
  --fill: 0%;
}
.track::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
  height: 4px;
  border-radius: 999px;
  background: rgba(20, 12, 14, .14);
}
.track__fill {
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  height: 4px;
  width: var(--fill);
  border-radius: 999px;
  background: var(--wine);
  transition: width var(--slide);
}
.track__thumb {
  position: absolute;
  top: 50%;
  left: var(--fill);
  transform: translate(-50%, -50%);
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--wine);
  box-shadow: 0 0 0 4px rgba(144, 0, 40, .18);
  transition: left var(--slide), box-shadow .2s var(--ease);
  pointer-events: none;
}
.track.is-scrubbing .track__fill,
.track.is-scrubbing .track__thumb { transition: none; }
.track:hover .track__thumb { box-shadow: 0 0 0 6px rgba(144, 0, 40, .28); }
.slider {
  position: absolute;
  inset: -6px 0;
  width: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; }
.slider::-moz-range-thumb { width: 26px; height: 26px; border: 0; }

/* ---------- Auto-hide UI ---------- */
.app.idle { cursor: none; }
.app.idle .topbar { opacity: 0; transform: translateY(-115%); pointer-events: none; }
.app.idle .controls { opacity: 0; transform: translateX(-50%) translateY(150%); pointer-events: none; }
.app.idle .edge { opacity: 0 !important; pointer-events: none; }

/* ---------- Loader ---------- */
.loader {
  position: absolute;
  inset: 0; z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: #ffffff;
  transition: opacity .6s var(--ease), visibility .6s var(--ease);
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
.loader__brand {
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
}
.loader__bar {
  width: min(280px, 62vw);
  height: 3px;
  border-radius: 999px;
  background: rgba(20, 12, 14, .1);
  overflow: hidden;
}
.loader__bar span {
  display: block;
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--wine-deep), var(--wine-lift));
  transition: width .3s var(--ease);
}
.loader__text {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .brand__sub { display: none; }
  .brand__logo { height: 34px; }
  .ctl__divider, #btn-first, #btn-last { display: none; }
  .controls { gap: 2px; padding: 7px 10px; }
  .pager { min-width: 42vw; }
  .stage { padding: 66px 8px 88px; }
}

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