:root {
  --bg: #090909;
  --panel: #111111;
  --panel-2: #171717;
  --text: #f5f5f1;
  --muted: #a5a5a0;
  --accent: #f2b51d;
  --line: rgba(255,255,255,.12);
  --page-ratio: 0.70710678; /* A4 width / height */
  --radius: 5px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(circle at 50% 45%, rgba(242,181,29,.055), transparent 33rem),
    var(--bg);
}

.topbar {
  min-height: 76px;
  padding: 14px clamp(16px, 3vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(9,9,9,.88);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 20;
}
.brand {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.brand-mark {
  width: 44px;
  flex: 0 0 44px;
  color: var(--accent);
  font-weight: 950;
  font-size: 13px;
  letter-spacing: -.07em;
  line-height: .78;
}
.brand-copy { min-width: 0; display: grid; gap: 3px; }
.brand-copy strong { font-size: 13px; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-copy small { font-size: 11px; color: var(--muted); white-space: nowrap; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.text-button,
.icon-button,
.nav-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.035);
  text-decoration: none;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.text-button:hover,
.icon-button:hover,
.nav-button:hover:not(:disabled) { background: rgba(255,255,255,.085); border-color: rgba(255,255,255,.22); }
.text-button:active,
.icon-button:active,
.nav-button:active:not(:disabled) { transform: translateY(1px); }
.text-button { padding: 10px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.icon-button {
  width: 38px; height: 38px; padding: 9px; border-radius: 50%; cursor: pointer;
}
.icon-button svg,
.nav-button svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.viewer {
  min-height: 0;
  padding: clamp(18px, 3vh, 30px) clamp(12px, 2vw, 24px) 12px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 12px;
}
.stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
  perspective: 2200px;
}
.book-wrap {
  --book-h: min(70vh, calc(100vw / (2 * var(--page-ratio))));
  position: relative;
  height: var(--book-h);
  aspect-ratio: calc(2 * var(--page-ratio)) / 1;
  max-width: calc(100vw - 120px);
  transform-style: preserve-3d;
}
.book-wrap.cover-mode {
  aspect-ratio: var(--page-ratio) / 1;
}
.book {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
}
.page {
  position: absolute;
  top: 0;
  width: 50%; height: 100%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
  backface-visibility: hidden;
  will-change: transform;
}
.page.left { left: 0; border-radius: var(--radius) 0 0 var(--radius); transform-origin: right center; }
.page.right { right: 0; border-radius: 0 var(--radius) var(--radius) 0; transform-origin: left center; }
.cover-mode .page { width: 100%; left: 0; right: auto; border-radius: var(--radius); }
.page img { width: 100%; height: 100%; display: block; object-fit: cover; user-select: none; -webkit-user-drag: none; }
.page.left::after,
.page.right::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 7%; pointer-events: none;
}
.page.left::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.18), transparent); }
.page.right::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,.16), transparent); }
.cover-mode .page::after { display: none; }

.book-shadow {
  position: absolute;
  z-index: -1;
  left: 5%; right: 5%; bottom: -28px;
  height: 36px;
  background: rgba(0,0,0,.75);
  filter: blur(20px);
  border-radius: 50%;
  transform: translateZ(-40px);
}
.spine {
  position: absolute; z-index: 8; top: 0; bottom: 0; left: 50%; width: 1px;
  background: rgba(0,0,0,.18); box-shadow: 0 0 16px rgba(0,0,0,.25); pointer-events: none;
}

.flip-layer {
  position: absolute; z-index: 12; top: 0; height: 100%; width: 50%;
  transform-style: preserve-3d;
  pointer-events: none;
}
.flip-layer.next { right: 0; transform-origin: left center; animation: flipNext .58s cubic-bezier(.65,.05,.36,1) both; }
.flip-layer.prev { left: 0; transform-origin: right center; animation: flipPrev .58s cubic-bezier(.65,.05,.36,1) both; }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; background: #fff; }
.flip-face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flip-face.back { transform: rotateY(180deg); }
.flip-layer.next .front { border-radius: 0 var(--radius) var(--radius) 0; }
.flip-layer.next .back { border-radius: var(--radius) 0 0 var(--radius); }
.flip-layer.prev .front { border-radius: var(--radius) 0 0 var(--radius); }
.flip-layer.prev .back { border-radius: 0 var(--radius) var(--radius) 0; }

@keyframes flipNext { from { transform: rotateY(0deg); } to { transform: rotateY(-180deg); } }
@keyframes flipPrev { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } }

.edge-nav {
  position: absolute;
  z-index: 7;
  top: 0; bottom: 0;
  width: min(14vw, 160px);
  border: 0;
  background: transparent;
  cursor: pointer;
}
.edge-prev { left: 0; }
.edge-next { right: 0; }
.edge-nav:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

.controls {
  margin: 0 auto;
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: 1fr minmax(120px, 220px) 1fr;
  align-items: center;
  gap: 14px;
}
.nav-button {
  justify-self: start;
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 13px;
  border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 700;
}
.nav-button:last-child { justify-self: end; }
.nav-button svg { width: 18px; height: 18px; }
.nav-button:disabled { opacity: .35; cursor: not-allowed; }
.status { display: grid; gap: 7px; text-align: center; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.progress-track { height: 2px; background: rgba(255,255,255,.1); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.hint { margin: 0; text-align: center; color: #73736e; font-size: 11px; }
.footer {
  min-height: 38px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border-top: 1px solid var(--line); color: #696964; font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
}
.footer-divider { color: var(--accent); }

.app.is-fullscreen .topbar,
.app.is-fullscreen .footer { display: none; }
.app.is-fullscreen .viewer { min-height: 100dvh; }
.app.is-fullscreen .book-wrap { --book-h: min(85vh, calc(100vw / (2 * var(--page-ratio)))); }

@media (max-width: 720px) {
  .topbar { min-height: 64px; padding: 10px 14px; }
  .brand-copy small { display: none; }
  .brand-copy strong { max-width: 42vw; }
  .text-button { font-size: 0; width: 38px; height: 38px; padding: 0; position: relative; }
  .text-button::after { content: "↓"; font-size: 18px; position: absolute; inset: 0; display: grid; place-items: center; }
  .viewer { padding: 18px 10px 10px; }
  .book-wrap,
  .book-wrap.cover-mode {
    --book-h: min(72vh, calc((100vw - 28px) / var(--page-ratio)));
    width: calc(var(--book-h) * var(--page-ratio));
    max-width: calc(100vw - 28px);
    aspect-ratio: var(--page-ratio) / 1;
  }
  .page, .cover-mode .page { width: 100%; left: 0; right: auto; border-radius: var(--radius); }
  .page.left, .page.right { left: 0; right: auto; border-radius: var(--radius); }
  .page.left::after, .page.right::after { display: none; }
  .spine { display: none; }
  .flip-layer, .flip-layer.next, .flip-layer.prev { left: 0; right: auto; width: 100%; transform-origin: left center; }
  .flip-layer.prev { transform-origin: right center; }
  .controls { grid-template-columns: 44px 1fr 44px; max-width: 420px; }
  .nav-button { width: 44px; padding: 0; justify-content: center; border-radius: 50%; }
  .nav-button:last-child { justify-self: end; }
  .nav-button span { display: none; }
  .hint { display: none; }
  .edge-nav { width: 26vw; }
  .app.is-fullscreen .book-wrap { --book-h: min(83vh, calc((100vw - 20px) / var(--page-ratio))); }
}

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

/* v2 interaction polish */
.brand-logo {
  width: 58px;
  height: 31px;
  object-fit: cover;
  object-position: center;
  border-radius: 3px;
  flex: 0 0 auto;
}
.top-actions { gap: 10px; }
.icon-button { position: relative; overflow: hidden; }
.sound-off { display: none; }
.icon-button.is-muted .sound-on { display: none; }
.icon-button.is-muted .sound-off { display: block; }
.stage-glow {
  position: absolute;
  width: min(72vw, 900px);
  height: 48%;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(242,181,29,.11), rgba(242,181,29,0) 68%);
  filter: blur(18px);
  pointer-events: none;
  z-index: -2;
}
.edge-nav {
  display: grid;
  place-items: center;
  opacity: .16;
  transition: opacity .2s ease, background .2s ease;
}
.edge-nav span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 50%;
  background: rgba(10,10,10,.38);
  backdrop-filter: blur(8px);
  font-size: 30px;
  line-height: 1;
  color: white;
}
.edge-nav:hover:not(:disabled) { opacity: .95; }
.edge-nav:disabled { opacity: 0; cursor: default; }
.book-wrap { transition: transform .25s ease; }
.book-wrap:hover { transform: translateY(-2px); }
.page { cursor: grab; }
.page:active { cursor: grabbing; }
.flip-layer {
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.30));
}
.flip-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.08) 46%, rgba(0,0,0,.26) 100%);
  mix-blend-mode: multiply;
  animation: curlShade .68s ease-in-out both;
}
.flip-layer.prev::before {
  background: linear-gradient(270deg, transparent 0%, rgba(255,255,255,.08) 46%, rgba(0,0,0,.26) 100%);
}
.flip-face.front::after,
.flip-face.back::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.26), transparent 16%, transparent 80%, rgba(255,255,255,.14));
  opacity: .65;
}
.flip-layer.prev .flip-face.front::after,
.flip-layer.prev .flip-face.back::after {
  background: linear-gradient(270deg, rgba(0,0,0,.26), transparent 16%, transparent 80%, rgba(255,255,255,.14));
}
@keyframes curlShade {
  0% { opacity: .12; transform: scaleX(.94); }
  46% { opacity: .92; transform: scaleX(1.02); }
  100% { opacity: .20; transform: scaleX(.95); }
}
.progress-bar { box-shadow: 0 0 10px rgba(242,181,29,.55); }
.status > span { color: #c8c8c2; }
.nav-button:hover:not(:disabled) { border-color: rgba(242,181,29,.45); }
.icon-button:hover { border-color: rgba(242,181,29,.45); }

@media (max-width: 720px) {
  .brand-logo { width: 48px; height: 26px; }
  .brand-copy strong { font-size: 12px; }
  .brand-copy small { display: none; }
  .edge-nav { opacity: 0; }
  .book-wrap:hover { transform: none; }
  .stage-glow { width: 96vw; height: 34%; }
}
