:root {
  color-scheme: dark;
  background: #050608;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  min-width: 320px;
  margin: 0;
  background: #050608;
}

body:has(dialog[open]) { overflow: hidden; }
button { -webkit-tap-highlight-color: transparent; }

.gallery {
  columns: 3 360px;
  column-gap: 8px;
  max-width: 1720px;
  margin: 0 auto;
  padding: 8px;
}

.tile {
  position: relative;
  width: 100%;
  display: inline-block;
  margin: 0 0 8px;
  padding: 0;
  overflow: hidden;
  break-inside: avoid;
  border: 0;
  border-radius: 5px;
  background: #101216;
  cursor: zoom-in;
  vertical-align: top;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: inherit;
  pointer-events: none;
  transition: border-color 180ms ease;
}

.tile img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 460ms cubic-bezier(0.2, 0.75, 0.25, 1), filter 220ms ease;
}

.tile:hover,
.tile:focus-visible { outline: none; }

.tile:hover::after,
.tile:focus-visible::after { border-color: rgba(255, 255, 255, 0.42); }

.tile:hover img,
.tile:focus-visible img {
  transform: scale(1.018);
  filter: brightness(1.04);
}

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(20px, env(safe-area-inset-top)) max(54px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(54px, env(safe-area-inset-left));
  overflow: hidden;
  border: 0;
  background: rgba(3, 4, 6, 0.97);
}

.lightbox::backdrop { background: rgba(0, 0, 0, 0.92); }

.preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  transition: opacity 180ms ease, filter 180ms ease;
}

.preview.loading-full {
  opacity: 0.82;
  filter: blur(1px);
}

.control {
  position: fixed;
  z-index: 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(8, 10, 14, 0.66);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.control:hover,
.control:focus-visible {
  border-color: rgba(255, 255, 255, 0.72);
  background: rgba(25, 29, 36, 0.88);
  outline: none;
}

.control svg {
  width: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.close {
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
}

.previous,
.next {
  top: 50%;
  transform: translateY(-50%);
}

.previous:hover,
.previous:focus-visible,
.next:hover,
.next:focus-visible { transform: translateY(-50%) scale(1.05); }

.previous { left: max(10px, env(safe-area-inset-left)); }
.next { right: max(10px, env(safe-area-inset-right)); }

@media (max-width: 980px) {
  .gallery {
    columns: 2 300px;
    column-gap: 6px;
    padding: 6px;
  }

  .tile { margin-bottom: 6px; }
}

@media (max-width: 560px) {
  .gallery {
    columns: 1;
    padding: 4px;
  }

  .tile {
    margin-bottom: 4px;
    border-radius: 4px;
  }

  .lightbox { padding: 48px 10px 62px; }

  .control {
    width: 38px;
    height: 38px;
  }

  .previous,
  .next {
    top: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: none;
  }

  .previous:hover,
  .previous:focus-visible,
  .next:hover,
  .next:focus-visible { transform: scale(1.05); }

  .previous { left: calc(50% - 52px); }
  .next { right: calc(50% - 52px); }
}

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