:root {
  color-scheme: dark;
  --bg: #080808;
  --panel: rgba(0, 0, 0, 0.78);
  --panel-soft: rgba(18, 18, 18, 0.72);
  --text: #f2f2f2;
  --muted: #a7a7a7;
  --line: rgba(255, 255, 255, 0.18);
  --accent: #dfdfdf;
  --focus: #fe4a4a;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 50% 18%, #252525 0, #101010 42%, #050505 100%),
    var(--bg);
}

button,
a {
  font: inherit;
}

.gallery-shell {
  width: min(1220px, calc(100vw - 28px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 14px;
}

.topbar,
.controls,
.thumb-strip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.topbar {
  min-height: 62px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.8vw, 2.05rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.counter {
  min-width: 78px;
  padding: 8px 10px;
  color: var(--accent);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.viewer {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
}

.photo-frame {
  position: relative;
  min-width: 0;
  height: min(72dvh, 760px);
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.photo-frame picture {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.photo-frame img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 1;
  transition: opacity 170ms ease, transform 220ms ease;
}

.photo-frame.is-loading img {
  opacity: 0;
  transform: scale(0.992);
}

.photo-frame figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 58px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.84) 30%);
}

#title {
  font-weight: 700;
}

#description {
  color: var(--muted);
  text-align: right;
}

.nav,
.controls button,
.controls a {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.nav {
  width: 54px;
  height: 70px;
  display: grid;
  place-items: center;
  font-size: 3rem;
  line-height: 1;
}

.nav:hover,
.controls button:hover,
.controls a:hover {
  border-color: rgba(255, 255, 255, 0.44);
  background: rgba(255, 255, 255, 0.13);
}

.controls {
  min-height: 62px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.controls button,
.controls a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
}

.thumb-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 106px;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  scrollbar-color: var(--accent) rgba(255, 255, 255, 0.12);
}

.thumb {
  width: 106px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 7px;
  background: #111;
  cursor: pointer;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.7);
}

.thumb:focus-visible,
.nav:focus-visible,
.controls button:focus-visible,
.controls a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

body.is-fullscreen .gallery-shell {
  width: min(1480px, calc(100vw - 18px));
}

@media (max-width: 760px) {
  .gallery-shell {
    width: min(100vw - 14px, 680px);
    min-height: auto;
    grid-template-rows: auto auto auto auto;
    gap: 10px;
    padding: 8px 0;
  }

  .topbar {
    min-height: 54px;
  }

  .viewer {
    grid-template-columns: 1fr;
  }

  .photo-frame {
    height: auto;
    aspect-ratio: 16 / 10;
  }

  .nav {
    position: absolute;
    z-index: 2;
    top: 50%;
    transform: translateY(-50%);
    width: 46px;
    height: 64px;
    background: rgba(0, 0, 0, 0.52);
  }

  .nav-prev {
    left: 6px;
  }

  .nav-next {
    right: 6px;
  }

  .photo-frame figcaption {
    display: block;
  }

  #description {
    display: block;
    margin-top: 3px;
    text-align: left;
  }

  .controls button,
  .controls a {
    flex: 1 1 138px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .photo-frame img {
    transition: none;
  }
}
