:root {
  --cor1: #3f276d;
  --cor1l: #7038ca;
  --cor1d: #2d1b4b;
  --cor2: #ee771b;
  --cor2l: #f29845;
  --branco: #fff;
  --texto-2: rgba(255, 255, 255, 0.64);
  --top-h: 72px;
  color-scheme: dark;
  font-family: "Poppins", Arial, Helvetica, sans-serif;
  color: var(--branco);
  background: #0c0814;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(63, 39, 109, 0.55), transparent 70%),
    radial-gradient(40% 40% at 100% 100%, rgba(238, 119, 27, 0.08), transparent 70%),
    #0c0814;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Topo ---------- */

.viewer-top {
  position: fixed;
  z-index: 5;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(12px, 2vw, 22px);
  min-height: var(--top-h);
  padding: max(12px, env(safe-area-inset-top)) clamp(14px, 3vw, 32px) 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(12, 8, 20, 0.78);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--branco);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 180ms ease, border-color 180ms ease;
}

.back-button svg {
  width: 22px;
  height: 22px;
  transition: transform 180ms ease;
}

.back-button:hover,
.back-button:focus-visible {
  border-color: rgba(242, 152, 69, 0.7);
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.back-button:hover svg {
  transform: translateX(-3px);
}

.doc-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.doc-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--cor2l);
  background: rgba(238, 119, 27, 0.14);
}

.doc-icon svg {
  width: 20px;
  height: 20px;
}

.doc-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.doc-title {
  margin: 0;
  overflow: hidden;
  font-size: clamp(0.92rem, 1.4vw, 1.05rem);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.doc-meta {
  color: var(--texto-2);
  font-size: 0.74rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.read-progress {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
}

.read-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--cor1l), var(--cor2l));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 120ms linear;
}

/* ---------- Botões ---------- */

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.8);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: color 160ms ease, background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.icon-button svg {
  width: 21px;
  height: 21px;
}

.icon-button:hover {
  color: var(--branco);
  background: rgba(255, 255, 255, 0.09);
}

.icon-button:active {
  transform: scale(0.92);
}

.icon-button:disabled {
  opacity: 0.3;
  cursor: default;
  background: transparent;
  transform: none;
}

.icon-button:focus-visible,
.zoom-label:focus-visible,
.state-action:focus-visible {
  outline: 2px solid var(--cor2l);
  outline-offset: 2px;
}

.icon-exit,
.is-fullscreen .icon-enter {
  display: none;
}

.is-fullscreen .icon-exit {
  display: block;
}

/* ---------- Páginas ---------- */

.viewer {
  position: fixed;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
  outline: none;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 2vw, 24px);
  width: max-content;
  min-width: 100%;
  padding: calc(var(--top-h) + 24px) clamp(12px, 3vw, 32px) 120px;
}

.pdf-page {
  position: relative;
  flex: none;
  overflow: hidden;
  border-radius: 6px;
  background: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06),
    0 24px 60px -18px rgba(0, 0, 0, 0.7),
    0 10px 24px -12px rgba(0, 0, 0, 0.5);
  animation: page-in 500ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: var(--delay, 0ms);
}

.pdf-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, #f1eef6 30%, #faf9fc 50%, #f1eef6 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}

.pdf-page.is-rendered::before {
  display: none;
}

.pdf-page canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.page-number {
  position: absolute;
  z-index: 3;
  right: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--branco);
  background: rgba(12, 8, 20, 0.66);
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.pdf-page:hover .page-number {
  opacity: 1;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

@keyframes shimmer {
  to {
    background-position: -300% 0;
  }
}

/* Camada de texto do PDF.js (permite selecionar e copiar) */
.textLayer {
  position: absolute;
  z-index: 2;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  text-align: initial;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
}

.textLayer :is(span, br) {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer span.markedContent {
  top: 0;
  height: 0;
}

.textLayer ::selection {
  background: rgba(238, 119, 27, 0.32);
}

.textLayer br::selection {
  background: transparent;
}

.textLayer .endOfContent {
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  display: block;
  cursor: default;
  user-select: none;
}

.textLayer.selecting .endOfContent {
  top: 0;
}

/* ---------- Dock inferior ---------- */

.dock {
  position: fixed;
  z-index: 5;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(16, 11, 26, 0.86);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateX(-50%);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  animation: dock-in 520ms 200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transition: opacity 260ms ease, transform 260ms ease;
}

.dock.is-idle {
  opacity: 0.35;
}

.dock.is-idle:hover,
.dock.is-idle:focus-within {
  opacity: 1;
}

@keyframes dock-in {
  from {
    opacity: 0;
    transform: translate(-50%, 24px);
  }
}

.page-field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.page-field input {
  width: 3.2ch;
  min-width: 42px;
  height: 34px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease;
}

.page-field input:focus {
  border-color: var(--cor2l);
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.page-total {
  color: var(--texto-2);
  white-space: nowrap;
}

.dock-divider {
  width: 1px;
  height: 24px;
  margin: 0 6px;
  background: rgba(255, 255, 255, 0.14);
}

.zoom-label {
  min-width: 64px;
  height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.zoom-label:hover {
  background: rgba(255, 255, 255, 0.08);
}

.zoom-label.is-auto {
  color: var(--cor2l);
}

/* ---------- Estados ---------- */

.viewer-state {
  position: fixed;
  z-index: 4;
  inset: var(--top-h) 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
}

.viewer-state p {
  max-width: 460px;
  margin: 0;
  color: var(--texto-2);
  line-height: 1.6;
}

.viewer-state h2 {
  margin: 8px 0 0;
  font-size: 1.3rem;
}

.viewer-state code {
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--cor2l);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.85em;
  word-break: break-all;
}

.state-spinner {
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--cor2l);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

.state-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 22px;
  color: var(--cor2l);
  background: rgba(238, 119, 27, 0.14);
  box-shadow: 0 0 0 8px rgba(238, 119, 27, 0.05);
}

.state-icon svg {
  width: 34px;
  height: 34px;
}

.state-action {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  margin-top: 18px;
  padding: 0 24px;
  border-radius: 999px;
  color: #1a0f2b;
  background: linear-gradient(135deg, var(--cor2l), var(--cor2));
  box-shadow: 0 12px 28px rgba(238, 119, 27, 0.3);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

/* ---------- Aviso ---------- */

.toast {
  position: fixed;
  z-index: 6;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 72px);
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  color: #1a0f2b;
  background: var(--branco);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsivo ---------- */

@media (max-width: 640px) {
  :root {
    --top-h: 64px;
  }

  .back-button {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .back-button span,
  .doc-icon {
    display: none;
  }

  .pages {
    padding-inline: 8px;
  }

  .pdf-page {
    border-radius: 4px;
  }

  .dock-divider {
    margin: 0 2px;
  }

  .zoom-label {
    min-width: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
