:root {
  --bg: #ffffff;
  --ink: #121214;
  --muted: #74747c;
  --line: #e9e9ed;
  --fill: #f3f3f5;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
}

.shell {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding-left: clamp(1rem, 4vw, 2.5rem);
  padding-right: clamp(1rem, 4vw, 2.5rem);
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.mark {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
}

.mark svg {
  width: 1.05rem;
  height: 1.05rem;
}

.count {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Gallery ---------- */

main {
  padding-top: clamp(1.25rem, 3vw, 2rem);
  padding-bottom: clamp(3rem, 6vw, 5rem);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13.5rem), 1fr));
  gap: clamp(0.75rem, 1.6vw, 1.25rem);
}

.card {
  position: relative;
  min-width: 0;
}

.photo {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--fill);
  overflow: hidden;
  cursor: zoom-in;
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 600ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.photo:hover img,
.photo:focus-visible img {
  transform: scale(1.035);
}

.quick-download {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  display: grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.quick-download svg {
  width: 1rem;
  height: 1rem;
}

.card:hover .quick-download,
.quick-download:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.quick-download:hover {
  background: #fff;
}

.skeleton {
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: linear-gradient(100deg, #f1f1f3 30%, #fafafa 50%, #f1f1f3 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* ---------- Empty / error ---------- */

.message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 5rem 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

.message[hidden],
.grid[hidden] {
  display: none;
}

.message svg {
  width: 2.75rem;
  height: 2.75rem;
  opacity: 0.4;
}

.message p {
  margin: 0;
}

.message button {
  margin-top: 0.35rem;
  padding: 0.55rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.message button:hover {
  border-color: var(--ink);
}

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

.viewer {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #0a0a0b;
  color: #fff;
  overflow: hidden;
}

.viewer::backdrop {
  background: #0a0a0b;
}

.viewer:not([open]) {
  display: none;
}

.viewer-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(0.85rem, 2.5vw, 1.5rem);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}

.round {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background-color 150ms ease;
}

.round:hover {
  background: rgba(255, 255, 255, 0.24);
}

.round svg {
  width: 1.1rem;
  height: 1.1rem;
}

.round-spacer {
  width: 2.4rem;
  height: 2.4rem;
}

.counter {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

#viewer-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transform: translateY(-50%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background-color 150ms ease;
}

.nav:hover {
  background: rgba(255, 255, 255, 0.22);
}

.nav svg {
  width: 1.2rem;
  height: 1.2rem;
}

.nav.prev {
  left: clamp(0.75rem, 2.5vw, 1.5rem);
}

.nav.next {
  right: clamp(0.75rem, 2.5vw, 1.5rem);
}

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

.viewer-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(0.85rem, 2.5vw, 1.5rem);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
}

.filename {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1.05rem;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 150ms ease;
}

.download-button:hover {
  background: #e8e8e8;
}

.download-button svg {
  width: 1rem;
  height: 1rem;
}

/* ---------- Small screens ---------- */

@media (max-width: 560px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.55rem;
  }

  .photo,
  .skeleton {
    border-radius: 10px;
  }

  .quick-download {
    opacity: 1;
    transform: none;
    width: 1.95rem;
    height: 1.95rem;
    right: 0.45rem;
    bottom: 0.45rem;
  }

  .topbar-inner {
    min-height: 3.6rem;
  }

  .brand {
    font-size: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
