:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #171717;
  color: #f5f5f2;
  --topbar-height: 64px;
}

* { box-sizing: border-box; }

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

body { background: #171717; }

button, input { font: inherit; }

.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto;
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(16, 16, 16, .92);
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand {
  color: inherit;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbar { display: flex; align-items: center; gap: 6px; }

.icon-button, .open-link {
  min-width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  color: #f5f5f2;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s ease, opacity .2s ease;
}

.icon-button:hover, .open-link:hover { background: rgba(255, 255, 255, .11); }
.icon-button:disabled { opacity: .3; cursor: default; }
.icon-button:focus-visible, .open-link:focus-visible, input:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.page-counter { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #aaa; }
.page-counter input {
  width: 34px;
  padding: 3px 2px;
  border: 0;
  border-radius: 4px;
  color: #fff;
  background: rgba(255, 255, 255, .08);
  text-align: center;
  appearance: textfield;
}
.page-counter input::-webkit-inner-spin-button { appearance: none; }
.divider { width: 1px; height: 20px; margin: 0 4px; background: rgba(255, 255, 255, .14); }
.zoom-label { width: 44px; color: #aaa; font-size: 12px; text-align: center; }
.open-link { width: auto; padding: 0 15px; margin-left: 5px; background: #f3f3ef; color: #111; font-size: 12px; font-weight: 700; }
.open-link:hover { background: #fff; }

.viewer {
  min-height: 100vh;
  padding: calc(var(--topbar-height) + env(safe-area-inset-top) + 30px) 28px calc(48px + env(safe-area-inset-bottom));
  overflow: auto;
}

.pages { display: flex; flex-direction: column; align-items: center; gap: 28px; }
.page-shell {
  position: relative;
  flex: none;
  max-width: none;
  background: #262626;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .34);
}
.page-shell canvas { display: block; width: 100%; height: 100%; }
.page-shell.is-loading::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  inset: 50% auto auto 50%;
  margin: -11px;
  border: 2px solid rgba(255, 255, 255, .15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.status, .fallback {
  min-height: calc(100vh - var(--topbar-height) - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #aaa;
  font-size: 14px;
}
.status[hidden] { display: none; }
.status.is-error { flex-direction: column; text-align: center; }
.status a, .fallback a { color: #fff; }
.spinner { width: 20px; height: 20px; border: 2px solid #444; border-top-color: #eee; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 680px) {
  :root { --topbar-height: 56px; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .brand { font-size: 12px; letter-spacing: .08em; }
  .toolbar { gap: 2px; }
  .icon-button { min-width: 34px; width: 34px; height: 34px; }
  .desktop-control, .divider { display: none; }
  .open-link { height: 34px; padding: 0 11px; margin-left: 3px; }
  .viewer { padding: calc(var(--topbar-height) + env(safe-area-inset-top) + 12px) 10px calc(30px + env(safe-area-inset-bottom)); }
  .pages { gap: 12px; }
  .page-counter input { width: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
