:root {
  --red: #ed2829;
  --bg: #141414;
  --ink: #f7f4f1;
  --muted: rgba(247, 244, 241, 0.68);
  --bar: rgba(18, 18, 18, 0.92);
  --page-w: 1323;
  --page-h: 1819;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 42%, #2a2422 0%, var(--bg) 62%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.topbar,
.bottombar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 8px 12px;
  background: var(--bar);
  backdrop-filter: blur(10px);
}

.topbar {
  justify-content: space-between;
  min-height: 52px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  width: 10px;
  height: 28px;
  border-radius: 999px;
  background: var(--red);
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.01em;
}

#zoom-btn,
.bottombar > button,
.viewer-bar button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#zoom-btn svg,
.bottombar > button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#zoom-btn:active,
.bottombar > button:active,
.viewer-bar button:active {
  background: var(--red);
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px 12px;
  overflow: hidden;
}

#sizer {
  width: min(100%, calc((100dvh - 168px) * var(--page-w) / var(--page-h)));
  max-height: 100%;
  filter: drop-shadow(0 16px 36px rgba(0, 0, 0, 0.45));
  transform-origin: center center;
  touch-action: none;
}

#book {
  width: 100%;
  touch-action: none;
}

.page {
  background: #fff;
  overflow: hidden;
}

.page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.bottombar {
  min-height: 64px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.scrub {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.page-label {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--muted);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
}

#viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(8, 8, 8, 0.96);
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#viewer[hidden] {
  display: none;
}

#viewer-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

#viewer-img {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px 12px;
}

.viewer-bar button {
  width: auto;
  min-width: 44px;
  height: 44px;
  padding: 0 14px;
  font-size: 20px;
  line-height: 1;
}

#zoom-close {
  font-size: 15px;
  font-weight: 650;
  background: var(--red);
}

#zoom-level {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--muted);
}

.viewer-hint {
  margin: 0;
  padding: 0 16px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: var(--bg);
  text-align: center;
}

.boot p {
  margin: 0;
  color: var(--muted);
}

body:not(.is-booting) .boot {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--red);
  animation: spin 0.7s linear infinite;
}

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

@media (pointer: coarse) {
  #zoom-btn {
    display: none;
  }
}

@media (max-width: 700px) {
  #stage {
    padding: 4px 0 6px;
  }

  .topbar,
  .bottombar {
    padding-left: 8px;
    padding-right: 8px;
  }
}


@media (orientation: landscape) and (max-height: 520px) {
  .topbar,
  .bottombar {
    position: absolute;
    z-index: 6;
    background: transparent;
    border: 0;
    backdrop-filter: none;
  }

  .topbar {
    top: 8px;
    left: 10px;
    right: 10px;
    min-height: 0;
    padding: 0;
  }

  .bottombar {
    top: 64px;
    right: 8px;
    bottom: 8px;
    left: 8px;
    min-height: 0;
    padding: 0;
    pointer-events: none;
    align-items: center;
    justify-content: space-between;
  }

  .bottombar > button,
  .scrub {
    pointer-events: auto;
  }

  .scrub {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: min(240px, 36vw);
    transform: translateX(-50%);
  }

  #stage {
    position: absolute;
    inset: 0;
    padding: 8px 60px 68px;
  }

  .viewer-hint {
    display: none;
  }
}
