:root {
  --bg: #FBF7F2;
  --ink: #4A2E25;
  --brown: #613420;
  --muted: #7A6258;
  --primary: #C8372D;
  --primary-dark: #9E2A22;
  --line: rgba(97, 52, 32, .14);
  --glass: rgba(255, 255, 255, .72);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(120% 80% at 50% 0%, #fff 0%, var(--bg) 45%, #F1E6D8 100%);
  color: var(--ink);
  font: 500 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible { outline: 3px solid #008cb8; outline-offset: 3px; }

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 #fff, 0 8px 18px -12px rgba(74, 46, 37, .45);
  color: var(--brown);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .15s, filter .15s, opacity .15s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn.round { width: 46px; padding: 0; flex: none; }
.btn.primary {
  border-color: transparent;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 10px 20px -10px rgba(200, 55, 45, .8);
  color: #fff;
}
.btn.dark {
  border-color: rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .1);
  box-shadow: none;
  color: #fff;
}
@media (hover: hover) {
  .btn:not(:disabled):hover { filter: brightness(.95); }
  .btn.dark:not(:disabled):hover { filter: brightness(1.4); }
}

/* ── Cabeçalho ── */
.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 58px;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; height: 44px; flex: none; }
.brand img { display: block; width: auto; height: 36px; }
.heading { display: none; min-width: 0; }
.heading span {
  display: block;
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.heading h1 {
  margin: 1px 0 0;
  overflow: hidden;
  font-size: 17px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.actions .btn { height: 44px; font-size: 14px; }
.actions .btn.round { width: 44px; }
.actions small { font-size: 12px; font-weight: 500; opacity: .85; }

/* ── Palco do livro ── */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px 6px;
}
.frame {
  flex: none;
  border-radius: 3px;
  box-shadow: 0 16px 28px -14px rgba(56, 37, 20, .5), 0 2px 6px rgba(56, 37, 20, .12);
  cursor: pointer;
}
.frame.spread { box-shadow: none; filter: drop-shadow(0 14px 16px rgba(56, 37, 20, .22)); }
/* A biblioteca define min/max-width inline; o tamanho é controlado por .frame (reader.js).
   touch-action: none mantém os touchmove canceláveis, senão o arraste da página morre no celular. */
#book { min-width: 0 !important; min-height: 0 !important; max-width: none !important; overflow: hidden; border-radius: 3px; touch-action: none; }
.frame.spread #book { overflow: visible; }
.page { overflow: hidden; background: #fff; }
.page img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#loading, .hint {
  position: absolute;
  left: 50%;
  margin: 0;
  padding: 9px 16px;
  border-radius: 999px;
  transform: translateX(-50%);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
#loading { top: 50%; background: #fff; box-shadow: 0 8px 20px -10px rgba(56, 37, 20, .5); transform: translate(-50%, -50%); }
.hint {
  bottom: 16px;
  width: max-content;
  max-width: calc(100% - 24px);
  background: rgba(46, 30, 24, .82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  transition: opacity .5s;
}
.hint.off { opacity: 0; }

/* ── Barra de navegação ── */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.pager { position: relative; flex: 1; max-width: 150px; min-width: 0; padding: 0 12px; font-variant-numeric: tabular-nums; }
.pager .i { width: 16px; height: 16px; opacity: .6; }
.pager select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}
.pager:focus-within { outline: 3px solid #008cb8; outline-offset: 3px; }

/* ── Leitura ampliada ── */
#viewer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: #241813;
  color: #fff;
}
#viewer[open] { display: flex; flex-direction: column; }
#viewer::backdrop { background: #241813; }
.vbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 58px;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.vbar .btn { height: 44px; }
.vbar .btn.round { width: 44px; }
#vstatus { font-size: 14px; font-variant-numeric: tabular-nums; opacity: .8; }
.zoomctl { display: flex; align-items: center; gap: 4px; }
#zlevel { min-width: 44px; font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; opacity: .8; }
.scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}
.scroller:focus { outline: none; }
#large {
  display: block;
  max-width: none;
  height: auto;
  margin: 0 auto;
  aspect-ratio: 148 / 210;
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.btn.dark.varrow {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-color: rgba(255, 255, 255, .3);
  background: rgba(36, 24, 19, .78);
  box-shadow: 0 8px 20px -6px rgba(0, 0, 0, .6);
}
.btn.dark.varrow:disabled { opacity: 0; pointer-events: none; }
#vprev { left: max(14px, env(safe-area-inset-left)); }
#vnext { right: max(14px, env(safe-area-inset-right)); }

.noscript { padding: 24px; text-align: center; }

/* ── Telas muito estreitas ── */
@media (max-width: 349px) {
  .actions small { display: none; }
  .bar { gap: 6px; }
  .bar .btn:not(.round) { padding: 0 12px; }
}

/* ── Celular deitado: menos cromo, mais página ── */
@media (max-height: 480px) {
  .top { height: 50px; }
  .brand img { height: 30px; }
  .actions .btn { height: 40px; }
  .actions .btn.round { width: 40px; }
  .stage { padding: 6px 8px 2px; }
  .bar { padding-top: 4px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .bar .btn { height: 42px; }
  .bar .btn.round { width: 42px; }
  .hint { display: none; }
}

/* ── Telas maiores ── */
@media (min-width: 520px) {
  .heading { display: block; }
}
@media (min-width: 768px) and (min-height: 481px) {
  .top { height: 68px; padding: 0 28px; gap: 22px; }
  .brand img { height: 42px; }
  .heading h1 { font-size: 20px; }
  .stage { padding: 20px 24px 10px; }
  .bar { gap: 12px; padding-bottom: 18px; }
  .pager { max-width: 170px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .hint { transition: none; }
}
