:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6f6a62;
  --line: #e2ddd5;
  --accent: #b4532a;
  --reader-bg: #2a2724;
  --reader-bar: #1f1d1b;
  --reader-text: #f1ede7;
  --reader-muted: #a59e94;
  --radius: 10px;
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #211f1d;
    --text: #efebe5;
    --muted: #9c958b;
    --line: #34312d;
    --accent: #e0835a;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

#app {
  min-height: 100%;
}

button,
input {
  font: inherit;
}

.status {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}
.status.error {
  color: #d9534f;
}

/* ---------- reader ---------- */
.reader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--reader-bg);
  color: var(--reader-text);
  color-scheme: dark;
}
.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  background: var(--reader-bar);
  min-height: 48px;
}
.bar.bottom {
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
.bar .title {
  margin: 0 8px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spacer {
  flex: 1;
}
.btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.btn:hover {
  background: rgb(255 255 255 / 0.08);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
}
.btn:disabled {
  opacity: 0.3;
  cursor: default;
  background: none;
}
.btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.indicator {
  min-width: 84px;
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--reader-muted);
}
.bar input[type='range'] {
  flex: 1;
  min-width: 60px;
  accent-color: var(--accent);
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}
.stage .status {
  color: var(--reader-muted);
}
.book {
  flex: none;
}
.page {
  background: #fff;
  overflow: hidden;
}
.page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  opacity: 0;
  transition: opacity 0.2s;
  user-select: none;
  -webkit-user-drag: none;
}
.page.ready img {
  opacity: 1;
}
.page-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #b7b0a6;
  font-size: 14px;
}
.page.failed .page-num::after {
  content: ' · could not load';
}

@media (max-width: 560px) {
  .stage {
    padding: 8px 0;
  }
  .indicator {
    min-width: 64px;
    font-size: 13px;
  }
  .bar .btn[title^='First'],
  .bar .btn[title^='Last'] {
    display: none;
  }
}

/* ---------- zoom ---------- */
.zoom {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: rgb(20 19 18 / 0.97);
}
.zoom-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  cursor: grab;
  touch-action: pan-x pan-y pinch-zoom;
}
.zoom-scroll.dragging {
  cursor: grabbing;
}
.zoom-sheet {
  display: flex;
  justify-content: center;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  align-items: center;
  padding: 16px;
  margin: 0 auto;
}
.zoom-sheet img {
  display: block;
  height: auto;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}
