:root {
  color-scheme: dark;
  --tagbar-height: 4rem;
  --bridge-color: hsla(218, 32%, 13%, 0.28);
  --app-bg: #090b10;
  --tagbar-bg: rgba(8, 10, 14, 0.74);
  --tagbar-border: rgba(255, 255, 255, 0.1);
  --tag-color: #f5f7ff;
  --tag-border: rgba(255, 255, 255, 0.25);
  --tag-bg: rgba(255, 255, 255, 0.08);
  --tag-bg-hover: rgba(255, 255, 255, 0.16);
  --tag-bg-active: rgba(191, 217, 255, 0.22);
  --tag-border-active: rgba(191, 217, 255, 0.8);
  --caption-color: rgba(229, 235, 248, 0.86);
  --caption-bg: rgba(255, 255, 255, 0.06);
  --caption-border: rgba(255, 255, 255, 0.14);
  --chip-color: #eef1ff;
  --chip-bg: rgba(255, 255, 255, 0.14);
  --chip-border: rgba(255, 255, 255, 0.32);
  --viewer-bg: rgba(6, 8, 12, 0.96);
  --viewer-hint-color: rgba(242, 246, 255, 0.92);
  --viewer-hint-border: rgba(255, 255, 255, 0.2);
  --viewer-hint-bg: rgba(0, 0, 0, 0.38);
}

html[data-theme="light"] {
  color-scheme: light;
  --bridge-color: hsla(214, 30%, 92%, 0.82);
  --app-bg: #eef2f7;
  --tagbar-bg: rgba(246, 249, 253, 0.84);
  --tagbar-border: rgba(15, 23, 42, 0.12);
  --tag-color: #1b2430;
  --tag-border: rgba(27, 36, 48, 0.24);
  --tag-bg: rgba(19, 32, 53, 0.06);
  --tag-bg-hover: rgba(19, 32, 53, 0.14);
  --tag-bg-active: rgba(34, 92, 183, 0.16);
  --tag-border-active: rgba(34, 92, 183, 0.5);
  --caption-color: rgba(23, 34, 48, 0.9);
  --caption-bg: rgba(20, 32, 50, 0.06);
  --caption-border: rgba(20, 32, 50, 0.18);
  --chip-color: rgba(23, 34, 48, 0.92);
  --chip-bg: rgba(20, 32, 50, 0.1);
  --chip-border: rgba(20, 32, 50, 0.24);
  --viewer-bg: rgba(245, 248, 252, 0.97);
  --viewer-hint-color: rgba(19, 29, 42, 0.95);
  --viewer-hint-border: rgba(19, 29, 42, 0.22);
  --viewer-hint-bg: rgba(245, 248, 252, 0.72);
}

* {
  box-sizing: border-box;
  font-family: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

html {
  scroll-behavior: smooth;
  background: transparent;
}

body {
  background: transparent;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: transparent;
}

#tag-bar {
  min-height: var(--tagbar-height);
  max-height: var(--tagbar-height);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 0;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
  background: var(--tagbar-bg);
  border-bottom: 1px solid var(--tagbar-border);
}

.tag-btn {
  border: 0;
  background: transparent;
  color: var(--tag-color);
  border-radius: 0;
  font-size: 0.88rem;
  line-height: 1;
  padding: 0.45rem 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 220ms ease, border-color 220ms ease;
}

.tag-btn:hover {
  background: transparent;
}

.tag-btn.is-active {
  background: transparent;
}

.theme-toggle {
  margin-left: 0;
}

.view-toggle {
  margin-left: auto;
}

.profile-toggle {
  margin-left: 0;
}

.icon-toggle {
  min-width: 2rem;
  padding: 0.45rem 0.55rem;
  font-size: 1.02rem;
}

#gallery {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
  background: var(--bridge-color);
  transition: background-color 1800ms cubic-bezier(0.22, 1, 0.36, 1);
}

#gallery.is-metro {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
  align-content: start;
  padding: 0.9rem;
  scroll-snap-type: none;
}

#gallery.is-metro .photo-section {
  min-height: auto;
  height: auto;
  padding: 0.65rem;
  gap: 0.55rem;
  scroll-snap-align: none;
  scroll-snap-stop: normal;
  overflow: visible;
}

#gallery.is-metro .photo-frame:not(.is-expanded) {
  width: 100%;
  height: 240px;
}

#gallery.is-metro .photo {
  opacity: 1;
  transform: none;
  transition-delay: 0ms, 0ms;
}

#gallery.is-metro .caption {
  width: 100%;
  padding: 0.45rem 0.55rem;
  font-size: 0.74rem;
}

#gallery.is-metro .chip-row {
  width: 100%;
  justify-content: flex-start;
}

#gallery.is-metro .chip {
  font-size: 0.7rem;
  padding: 0.28rem 0.45rem;
}

#gallery.is-profile {
  scroll-snap-type: none;
  overflow: auto;
  padding: 1rem;
}

.profile-view {
  min-height: calc(100svh - var(--tagbar-height));
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.profile-visual,
.profile-copy {
  background: transparent;
  min-height: 0;
}

.profile-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.profile-copy {
  display: flex;
  align-items: center;
}

.profile-caption {
  margin: 0;
  color: var(--caption-color);
  font-size: 0.88rem;
  line-height: 1.5;
  text-transform: none;
}

body.viewer-active #gallery.is-metro .photo-section {
  opacity: 0;
  pointer-events: none;
}

body.viewer-active #gallery.is-metro .photo-section.is-fullscreen-source {
  opacity: 1;
  pointer-events: auto;
}

body.viewer-active #gallery {
  overflow: hidden;
}

.photo-section {
  position: relative;
  width: 100%;
  min-height: calc(100svh - var(--tagbar-height));
  height: calc(100svh - var(--tagbar-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1.1rem;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  transition: background-color 1500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.photo-frame {
  width: min(100%, 1400px);
  height: min(82%, 920px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.photo-frame.is-expanded {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  max-width: none;
  height: 100svh;
  z-index: 100;
  padding: 1.25rem;
  overflow: auto;
  background: var(--viewer-bg);
  cursor: zoom-out;
}

.photo-frame.is-expanded::after {
  content: "Tap image again or press Esc to close";
  position: fixed;
  left: 50%;
  bottom: 1.15rem;
  transform: translateX(-50%);
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.42rem 0.72rem;
  color: var(--viewer-hint-color);
  border: 1px solid var(--viewer-hint-border);
  border-radius: 0;
  background: var(--viewer-hint-bg);
  pointer-events: none;
}

.photo {
  display: block;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.985);
  transition: opacity 2300ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 2700ms cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: 0ms, 0ms;
  will-change: opacity, transform;
}

.photo-frame.is-expanded .photo.is-original-size {
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
}

.original-size-toggle {
  display: none;
  position: static;
  z-index: 102;
  border: 0;
  background: transparent;
  color: var(--viewer-hint-color);
  border-radius: 0;
  min-width: 3.45rem;
  height: 3.45rem;
  padding: 0;
  line-height: 1;
  font-size: 1.85rem;
  cursor: pointer;
}

.original-size-toggle-wrap {
  display: none;
  position: fixed;
  top: 50%;
  left: 0;
  transform: translate(0, -50%);
  z-index: 101;
  overflow: visible;
  pointer-events: none;
}

.photo-frame.is-expanded .original-size-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.photo-frame.is-expanded .original-size-toggle-wrap {
  display: block;
}

.photo-section.is-visible .photo {
  opacity: 1;
  transform: scale(1);
  transition-delay: 850ms, 850ms;
}

.caption {
  margin: 0;
  width: min(100%, 920px);
  text-align: center;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  color: var(--caption-color);
  background: var(--caption-bg);
  border: 0;
  border-radius: 0;
  padding: 0.5rem 0.9rem;
  backdrop-filter: blur(3px);
}

.chip-row {
  width: min(100%, 1400px);
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: center;
}

.chip {
  border: 0;
  background: transparent;
  color: var(--chip-color);
  border-radius: 0;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.35rem 0.62rem;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  #gallery {
    scroll-behavior: auto;
  }

  .photo {
    transition: none;
    transition-delay: 0ms, 0ms;
    transform: none;
  }

  .tag-btn {
    transition: none;
  }
}

@media (max-width: 768px) {
  #gallery.is-metro {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view-toggle,
  .profile-toggle,
  .theme-toggle {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + var(--tagbar-height) + 0.3rem);
    z-index: 120;
    margin-left: 0;
  }

  .theme-toggle {
    right: 0.35rem;
  }

  .profile-toggle {
    right: 3.6rem;
  }

  .view-toggle {
    right: 8.35rem;
  }

  .profile-view {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    min-height: auto;
  }

  .photo-frame.is-expanded {
    padding: 0.75rem;
  }

  .photo-frame.is-expanded .photo.is-original-size {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100svh - 1.5rem);
    width: auto;
    height: auto;
    object-fit: contain;
  }
}