:root {
  color-scheme: dark;
  --bg: #111317;
  --panel: rgba(21, 24, 30, 0.86);
  --panel-soft: rgba(9, 11, 14, 0.78);
  --text: #f5f7fa;
  --muted: #b9c2cf;
  --line: rgba(255, 255, 255, 0.18);
  --accent: #71a9ff;
  --accent-strong: #b7d4ff;
}

* {
  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 22% 18%, rgba(113, 169, 255, 0.28), transparent 34%),
    linear-gradient(135deg, #161a22, #07080a 70%),
    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;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

.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: 82px;
  padding: 8px 10px;
  color: var(--accent-strong);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.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);
}

.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;
}

#meta {
  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(0, 0, 0, 0.28);
  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(183, 212, 255, 0.7);
  background: rgba(113, 169, 255, 0.17);
}

.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: 94px;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  scrollbar-color: var(--accent) rgba(255, 255, 255, 0.12);
}

.thumb {
  width: 94px;
  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-strong);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.66);
}

.thumb:focus-visible,
.nav:focus-visible,
.controls button:focus-visible,
.controls a:focus-visible {
  outline: 2px solid var(--accent-strong);
  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: 4 / 3;
  }

  .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;
  }

  #meta {
    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;
  }
}
