:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f7f7f5;
  color: #171717;
  font-synthesis: none;
  --toolbar-height: 52px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button {
  color: inherit;
  font: inherit;
}

.viewer {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(14px, 2.4vh, 26px);
  padding: clamp(16px, 3vw, 42px) clamp(12px, 4vw, 64px) clamp(16px, 2.5vh, 28px);
  background: radial-gradient(circle at 50% 42%, #ffffff 0, #fbfbfa 48%, #f4f4f1 100%);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(36px, 4vw, 58px) minmax(0, 1fr) clamp(36px, 4vw, 58px);
  align-items: center;
  outline: none;
}

.page-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

.page-track {
  width: 100%;
  height: 100%;
  display: flex;
  transform: translate3d(calc(var(--page-index, 0) * -100%), 0, 0);
  transition: transform 420ms var(--ease-out);
  will-change: transform;
}

.page-panel {
  min-width: 0;
  height: 100%;
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-surface {
  position: relative;
  flex: 0 0 auto;
  transform: translate3d(var(--pan-x, 0), var(--pan-y, 0), 0) scale(var(--page-scale, 1));
  transform-origin: center;
  box-shadow:
    0 2px 5px rgb(0 0 0 / 8%),
    0 18px 48px rgb(0 0 0 / 13%);
  transition: transform 220ms var(--ease-out);
  will-change: transform;
}

.portfolio-page {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  object-fit: contain;
  opacity: 0;
  transition: opacity 180ms ease;
  will-change: opacity;
}

.portfolio-page.is-loaded {
  opacity: 1;
}

.page-viewport.is-zoomed {
  cursor: grab;
}

.page-viewport.is-dragging {
  cursor: grabbing;
}

.page-viewport.is-dragging .page-surface {
  transition: none;
}

.page-link {
  position: absolute;
  z-index: 1;
  display: block;
  cursor: pointer;
  border-radius: 2px;
  background: transparent;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgb(91 124 255 / 20%);
}

.page-link:hover,
.page-link:focus-visible {
  background: rgb(91 124 255 / 10%);
  outline: 2px solid rgb(91 124 255 / 72%);
  outline-offset: 1px;
}

.page-arrow,
.tool-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.page-arrow {
  position: relative;
  z-index: 2;
  width: clamp(36px, 4vw, 50px);
  height: clamp(54px, 8vw, 80px);
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: #6b6b68;
  transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.page-arrow span {
  font: 300 clamp(38px, 5vw, 60px) / 1 Georgia, serif;
  transform: translateY(-3px);
}

.page-arrow:hover:not(:disabled) {
  color: #111;
  background: rgb(255 255 255 / 76%);
}

.page-arrow:active:not(:disabled) {
  transform: scale(0.94);
}

.page-arrow:disabled {
  cursor: default;
  color: #d3d3cf;
}

.page-arrow--previous {
  justify-self: start;
}

.page-arrow--next {
  justify-self: end;
}

.toolbar {
  justify-self: center;
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 8px 6px 16px;
  border: 1px solid rgb(0 0 0 / 8%);
  border-radius: 999px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 8px 28px rgb(0 0 0 / 10%);
  backdrop-filter: blur(14px);
}

.page-status {
  min-width: 50px;
  color: #4d4d4a;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  margin: 0 4px;
  background: #deded9;
}

.tool-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: #383835;
  font-size: 22px;
  line-height: 1;
  transition: background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.tool-button:hover:not(:disabled) {
  background: #f0f0ed;
  color: #000;
}

.tool-button:active:not(:disabled) {
  transform: scale(0.92);
}

.tool-button:disabled {
  cursor: default;
  color: #bdbdb9;
}

.reset-button {
  width: 54px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.fullscreen-button {
  font-size: 20px;
}

.page-loader,
.page-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-loader {
  gap: 6px;
  pointer-events: none;
}

.page-loader span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #a7a7a2;
  animation: loading-pulse 900ms ease-in-out infinite alternate;
}

.page-loader span:nth-child(2) {
  animation-delay: 150ms;
}

.page-loader span:nth-child(3) {
  animation-delay: 300ms;
}

.page-error {
  z-index: 3;
  flex-direction: column;
  gap: 12px;
  color: #555551;
  text-align: center;
}

.page-error[hidden],
.page-loader[hidden] {
  display: none;
}

.page-error p {
  margin: 0;
}

.text-button {
  padding: 9px 15px;
  border-radius: 999px;
  background: #1d1d1b;
  color: #fff;
  font-size: 13px;
}

button:focus-visible,
.stage:focus-visible {
  outline: 3px solid #5b7cff;
  outline-offset: 3px;
}

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

@keyframes loading-pulse {
  from { opacity: 0.25; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 640px) {
  .viewer {
    gap: 12px;
    padding: 10px 4px max(12px, env(safe-area-inset-bottom));
  }

  .stage {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
  }

  .page-arrow {
    width: 34px;
    height: 62px;
  }

  .page-arrow span {
    font-size: 42px;
  }

  .toolbar {
    max-width: calc(100vw - 16px);
    height: 48px;
    padding: 5px 7px 5px 12px;
  }

  .tool-button {
    width: 34px;
    height: 34px;
  }

  .reset-button {
    width: 48px;
  }

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

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