:root {
  --ink: #171310;
  --paper: #f3ead8;
  --red: #e94520;
  --yellow: #f5ba2c;
  --topbar: 68px;
  --statusbar: 44px;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--paper);
  background:
    radial-gradient(circle at 15% 20%, #3a2e24 0 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(145deg, #211b17, #0c0a09 60%);
  font-family: "Avenir Next", "Futura", "Trebuchet MS", sans-serif;
}

button, select { font: inherit; }

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  height: calc(var(--topbar) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(8px, env(safe-area-inset-top)) clamp(12px, 3vw, 30px) 8px;
  background: #171310ed;
  border-bottom: 1px solid #ffffff20;
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--ink);
  background: var(--yellow);
  border: 2px solid var(--paper);
  border-radius: 50%;
  box-shadow: 4px 4px 0 var(--red);
  font: 900 24px/1 Georgia, serif;
}

.brand strong, .brand small { display: block; }
.brand strong { overflow: hidden; letter-spacing: .01em; text-overflow: ellipsis; white-space: nowrap; }
.brand small { margin-top: 2px; color: #c8bdad; font-size: 12px; }

.chapter-picker { display: flex; align-items: center; gap: 9px; }
.chapter-picker span { color: #c8bdad; font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

select {
  min-height: 42px;
  padding: 7px 34px 7px 11px;
  color: var(--paper);
  background: #2d2520;
  border: 1px solid #ffffff30;
  border-radius: 5px;
}

select:focus-visible, button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.viewer {
  position: fixed;
  inset: calc(var(--topbar) + env(safe-area-inset-top)) 0 calc(var(--statusbar) + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  touch-action: pinch-zoom;
  user-select: none;
}

.page {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 8px clamp(10px, 6vw, 78px);
}

.page img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 16px 54px #00000080;
  -webkit-user-drag: none;
}

.page-button {
  position: absolute;
  z-index: 5;
  top: 50%;
  width: 54px;
  height: 72px;
  transform: translateY(-50%);
  color: var(--paper);
  background: #171310d9;
  border: 1px solid #ffffff32;
  border-radius: 7px;
  font-size: 28px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.page-button:hover { color: var(--ink); background: var(--yellow); }
.page-button:disabled { visibility: hidden; }
.page-button.prev { left: clamp(8px, 2vw, 24px); }
.page-button.next { right: clamp(8px, 2vw, 24px); }

.loading {
  position: absolute;
  z-index: -1;
  color: #c8bdad;
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.statusbar {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: calc(var(--statusbar) + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px clamp(12px, 3vw, 30px) max(8px, env(safe-area-inset-bottom));
  color: #c8bdad;
  background: #171310ed;
  border-top: 1px solid #ffffff20;
  font-size: 12px;
  backdrop-filter: blur(14px);
}

.statusbar strong { color: var(--paper); text-align: center; }
.hint { text-align: right; }

@media (max-width: 800px) {
  :root { --topbar: 58px; --statusbar: 40px; }
  .topbar { gap: 8px; padding-right: 9px; padding-left: 9px; }
  .brand { gap: 8px; }
  .brand-mark { width: 36px; height: 36px; font-size: 21px; box-shadow: 3px 3px 0 var(--red); }
  .brand strong { max-width: 150px; font-size: 13px; }
  .brand small, .chapter-picker span { display: none; }
  select { width: 120px; min-height: 38px; padding: 5px 8px; }
  .page { padding: 4px 0; }
  .page img { box-shadow: none; }
  .page-button { display: none; }
  .statusbar { grid-template-columns: 1fr auto; padding-right: 10px; padding-left: 10px; }
  .hint { display: none; }
}
