:root {
  --fb-bg: #2b2f36;
  --fb-bar-bg: rgba(20, 22, 26, 0.92);
  --fb-text: #f2f4f7;
  --fb-muted: #a9b0bb;
  --fb-accent: #3d8bfd;
  --fb-bar-height: 52px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--fb-bg);
  color: var(--fb-text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.fb-bar {
  /* 封面硬翻时有 3D 透视，会探出书框，要压在工具栏下面 */
  position: relative;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--fb-bar-height);
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--fb-bar-bg);
}

.fb-bar--top {
  justify-content: space-between;
  gap: 12px;
  padding-top: env(safe-area-inset-top);
}

.fb-home {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--fb-text);
  font-size: 14px;
  text-decoration: none;
}

.fb-home:hover {
  background: rgba(255, 255, 255, 0.1);
}

.fb-home:focus-visible {
  outline: 2px solid var(--fb-accent);
  outline-offset: 2px;
}

.fb-home svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fb-bar--bottom {
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.fb-title {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.fb-stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* 手势全部由 viewer.js 处理，浏览器不要自己滚动或缩放 */
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.fb-error {
  margin: 0;
  color: var(--fb-muted);
  text-align: center;
}

/* 加载时只转一个圈，不写字 */
.fb-loading {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--fb-muted);
  border-radius: 50%;
  animation: fb-spin 0.9s linear infinite;
}

@keyframes fb-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fb-loading {
    animation-duration: 3s;
  }
}

.fb-book-box[hidden],
.fb-loading[hidden],
.fb-error[hidden] {
  display: none;
}

/* 放大用 transform，原点在左上角，坐标换算见 viewer.js createZoom */
.fb-book-box {
  transform-origin: 0 0;
}

.fb-stage.is-zoomed {
  cursor: grab;
}

.fb-stage.is-zoomed:active {
  cursor: grabbing;
}

/* 翻页库按 minWidth 给外框写了行内最小宽度；外框宽度由 viewer.js 按舞台大小算，不要它撑大 */
.fb-book-box .stf__parent {
  min-width: 0 !important;
  min-height: 0 !important;
}

.fb-sheet {
  background: #fff;
}

.fb-sheet canvas {
  display: block;
}

.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fb-text);
  cursor: pointer;
}

.fb-btn[hidden] {
  display: none;
}

.fb-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.fb-btn:focus-visible {
  outline: 2px solid var(--fb-accent);
  outline-offset: 2px;
}

.fb-btn:disabled {
  color: #5c636e;
  cursor: default;
}

.fb-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fb-page {
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fb-sep {
  width: 1px;
  height: 24px;
  margin: 0 6px;
  background: rgba(255, 255, 255, 0.18);
}

/* 窄屏手机：七个按钮挤得下 */
@media (max-width: 400px) {
  .fb-btn {
    width: 40px;
  }

  .fb-sep {
    margin: 0 2px;
  }
}
