:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #000;
  color: #242321;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

.viewer {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 100svh;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: #000;
}

.artwork {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  perspective: 1500px;
  perspective-origin: 50% 50%;
  pointer-events: none;
}

.background, .slide {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
}

/* Keep the source background as its own permanent layer. */
.background { z-index: 0; }

.slide {
  z-index: 1;
  backface-visibility: hidden;
  opacity: 0;
  transform: translate3d(0, 0, 0) rotateY(0) scale(1);
  transform-origin: 50% 50%;
  transition: transform 860ms cubic-bezier(.2,.72,.2,1), opacity 860ms ease;
}

.slide.is-visible { opacity: 1; transform: translate3d(0, 0, 0) rotateY(0) scale(1); }
.slide.is-entering-next { opacity: 0; transform: translate3d(42%, 0, -220px) rotateY(-78deg) scale(.58); }
.slide.is-entering-before { opacity: 0; transform: translate3d(-42%, 0, -220px) rotateY(78deg) scale(.58); }
.slide.is-leaving-next { opacity: 0; transform: translate3d(-42%, 0, -220px) rotateY(78deg) scale(.58); }
.slide.is-leaving-before { opacity: 0; transform: translate3d(42%, 0, -220px) rotateY(-78deg) scale(.58); }

.nav {
  position: absolute;
  z-index: 3;
  top: 50%;
  display: grid;
  width: 48px;
  aspect-ratio: 791 / 836;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transform: translateY(-50%);
  transition: scale 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.nav:hover:not(:disabled) { scale: 1.07; }
.nav:active:not(:disabled) { scale: .96; }
.nav:focus-visible { outline: 2px solid #292725; outline-offset: 5px; }
.nav:disabled { opacity: 1; cursor: default; }
.nav img { width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.nav--before, .nav--next { right: auto; }

.go-link {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: auto;
  left: 0;
  display: block;
  width: 125px;
  line-height: 0;
  transform: translateX(-50%);
  -webkit-tap-highlight-color: transparent;
}
.go-link[hidden] { display: none; }
.go-link img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.go-link:focus-visible { outline: 2px solid #292725; outline-offset: 5px; }

.drawing-canvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}
.viewer.is-drawing { cursor: none; }
.drawing-canvas.is-active { pointer-events: auto; cursor: none; }

.comment-button {
  position: absolute;
  z-index: 4;
  display: block;
  width: 110px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  line-height: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.comment-button img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.comment-button:focus-visible, .reset-button:focus-visible, .swatch:focus-visible { outline: 2px solid #292725; outline-offset: 4px; }
.comment-button:disabled { opacity: .5; cursor: default; }

.drawing-tools { position: absolute; z-index: 4; inset: 0; pointer-events: none; }
.drawing-tools[hidden] { display: none; }
.reset-button {
  position: absolute;
  top: 0;
  right: auto;
  width: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  line-height: 0;
  cursor: pointer;
  pointer-events: auto;
}
.reset-button img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.color-palette {
  position: absolute;
  top: 50%;
  right: clamp(18px, 3vw, 42px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(-50%);
  pointer-events: auto;
}
.swatch {
  width: 27px;
  height: 27px;
  padding: 0;
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 50%;
  background: var(--swatch-color);
  box-shadow: 0 1px 5px rgba(0,0,0,.27);
  cursor: pointer;
}
.swatch[data-color="#ed2738"] { --swatch-color: #ed2738; }
.swatch[data-color="#2377e8"] { --swatch-color: #2377e8; }
.swatch[data-color="#f3cf28"] { --swatch-color: #f3cf28; }
.swatch[data-color="#28a85a"] { --swatch-color: #28a85a; }
.swatch[data-color="#171717"] { --swatch-color: #171717; }
.swatch[data-color="#ee68ad"] { --swatch-color: #ee68ad; }
.swatch--eraser { position: relative; background: #f7f4f0; }
.swatch--eraser span {
  display: block;
  width: 17px;
  height: 11px;
  margin: auto;
  border: 1px solid #71675f;
  border-radius: 2px;
  background: linear-gradient(135deg, #f1a8bd 0 48%, #fff 49% 100%);
  transform: rotate(-45deg);
}
.swatch.is-selected { outline: 2px solid #292725; outline-offset: 2px; }

.pencil-cursor {
  position: fixed;
  z-index: 5;
  display: none;
  width: 38px;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.pencil-cursor.is-visible { display: block; }

.counter {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 0;
  margin: 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: .18em;
  color: #302d29;
  opacity: .68;
  pointer-events: none;
}

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