/* #loading / #errorBox / #toolbar / #viewerContainer below are all toggled
   via the `hidden` attribute. The browser's built-in UA rule for that is
   `[hidden] { display: none }` with NO !important, so an ID-selector rule
   like `#errorBox { display: flex }` (higher specificity: 1-0-0 beats the
   attribute selector's 0-1-0) silently wins and keeps the element visible
   even while `hidden` is set. This was the actual bug behind the error
   overlay staying on screen no matter what the JS did: `errorBox.hidden`
   was being toggled correctly the whole time, but CSS specificity meant it
   never had any visual effect. This rule makes `hidden` authoritative
   regardless of any other rule's specificity. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #525659;
  overscroll-behavior: none;
}

#viewerContainer {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#viewer {
  position: relative;
}

.page-container {
  margin: 8px auto;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 640px) {
  .page-container {
    margin: 4px auto;
  }
}

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #525659;
  z-index: 20;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#errorBox {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #525659;
  color: #eee;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  text-align: center;
  padding: 24px;
  z-index: 30;
}

#errorBox button {
  font: inherit;
  padding: 6px 16px;
  border: 1px solid #888;
  border-radius: 4px;
  background: #3a3d40;
  color: #fff;
  cursor: pointer;
}

#errorBox button:hover {
  background: #47494c;
}

#toolbar {
  position: fixed;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(30, 30, 30, 0.55);
  border-radius: 6px;
  padding: 4px 6px;
  z-index: 10;
}

#toolbar button,
#toolbar a {
  font: 13px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #fff;
  background: transparent;
  border: none;
  padding: 6px 9px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}

#toolbar button:hover,
#toolbar a:hover {
  background: rgba(255, 255, 255, 0.15);
}

#toolbar > * + * {
  border-left: 1px solid rgba(255, 255, 255, 0.25);
}
