:root {
  --bg: #0b0b0d;
  --fg: #f4f1ea;
  --muted: rgba(244, 241, 234, 0.64);
  --accent: #f3c35b;
  --dot: rgba(244, 241, 234, 0.34);
  --dots-height: 52px;
  color-scheme: dark;
}

/* The app toggles visibility with the hidden attribute; make sure no display
   rule below can override it. */
[hidden] {
  display: none !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---- Loading / message / error screen ---------------------------------- */

.status {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  text-align: center;
}

.status-inner {
  max-width: 22rem;
}

.status-title {
  margin: 0 0 0.5rem;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status-text {
  margin: 0;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 20px;
  border: 3px solid rgba(244, 241, 234, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.retry-button {
  min-height: 44px;
  margin-top: 20px;
  padding: 10px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #15120a;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.retry-button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

/* ---- Viewer ----------------------------------------------------------- */

.viewer {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Native scroll-snap gives momentum, trackpad swipes and accessible
   scrolling for free, which hand-rolled touch handling would not. */
.track {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  /* No rubber-band at the ends, and no chaining into browser back/forward
     swipes or pull-to-refresh. */
  overscroll-behavior: none;
  scrollbar-width: none;
  outline: none;
}

.track::-webkit-scrollbar {
  display: none;
}

.track:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(243, 195, 91, 0.55);
}

.slide {
  display: flex;
  flex: 0 0 100%;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  scroll-snap-align: start;
  /* One slide per swipe, even on a hard flick. */
  scroll-snap-stop: always;
}

/* Deliberately no user-select or touch-callout overrides here: they would
   break long-press "Save image" on phones. */
.slide-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dots {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--dots-height);
  padding: 8px 16px max(8px, env(safe-area-inset-bottom));
}

/* The button is a comfortable tap target; the visible dot is drawn inside. */
.dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot);
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.dot[aria-current="true"]::before {
  background: var(--fg);
  transform: scale(1.3);
}

.dot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

/* Prev/next only where there is a mouse or trackpad; on phones swiping and
   the dots are enough, and the buttons would sit on top of the photos. */
.nav-button {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .nav-button {
    position: absolute;
    top: calc((100% - var(--dots-height)) / 2);
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: var(--fg);
    cursor: pointer;
    transform: translateY(-50%);
    transition: opacity 0.2s ease, background-color 0.2s ease;
  }

  .nav-button:hover {
    background: rgba(0, 0, 0, 0.75);
  }

  .nav-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .nav-button:disabled {
    opacity: 0;
    pointer-events: none;
  }

  .nav-prev {
    left: max(16px, env(safe-area-inset-left));
  }

  .nav-next {
    right: max(16px, env(safe-area-inset-right));
  }
}

/* Always shown, unlike prev/next: saving is the point of the page on a phone. */
.download-button {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: var(--fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

/* Disabled while the file is being fetched. */
.download-button:disabled {
  opacity: 0.5;
  cursor: progress;
}

.download-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .download-button:hover {
    background: rgba(0, 0, 0, 0.75);
  }
}

.download-message {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  right: max(12px, env(safe-area-inset-right));
  max-width: min(18rem, calc(100% - 24px));
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: var(--fg);
  font-size: 0.875rem;
}

@media (prefers-reduced-motion: reduce) {
  .dot::before,
  .nav-button,
  .download-button {
    transition: none;
  }
}
