:root {
  color-scheme: dark;
  --bg: #111;
  --fg: #eee;
  --muted: #aaa;
  --panel: #181818;
  --line: #2a2a2a;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-y: scroll;
}
#topbar {
  padding:
    calc(.85rem + env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    .9rem
    max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: #141414;
  position: sticky;
  top: 0;
  z-index: 10;
}
#topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.25;
}
#meta {
  margin-top: .35rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .9rem;
  align-items: center;
  width: 100%;
}
#count {
  color: var(--muted);
  font-size: .92rem;
}
#topnav {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
}
.top-link {
  color: inherit;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .45rem;
  padding: .35rem .6rem;
  font-size: .92rem;
}
.top-link:hover, .top-link:focus-visible {
  background: #202020;
}
#children-menu {
  position: relative;
}
#children-toggle {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  padding: 0;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .45rem;
  cursor: pointer;
  user-select: none;
  font-size: 1.15rem;
  line-height: 1;
}
#children-toggle::-webkit-details-marker {
  display: none;
}
#children-toggle::marker {
  content: "";
}
#children-toggle:hover, #children-toggle:focus-visible {
  background: #202020;
}
#children-panel {
  position: absolute;
  top: calc(100% + .45rem);
  right: 0;
  width: min(24rem, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  max-height: min(70vh, 36rem);
  overflow: auto;
  padding: .85rem;
  background: #141414;
  border: 1px solid var(--line);
  border-radius: .55rem;
  box-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .4);
  z-index: 30;
}
#children-panel h2 {
  margin: 0 0 .6rem;
  font-size: .95rem;
  color: var(--muted);
  font-weight: 600;
}
#children-panel ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin: 0;
  padding: 0;
}
#children-panel a {
  display: block;
  color: inherit;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .45rem;
  padding: .45rem .65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#children-panel a:hover, #children-panel a:focus-visible {
  background: #202020;
}
#gallery {
  width: 100%;
  position: relative;
  min-height: 1px;
}
.gallery-row {
  position: absolute;
  left: env(safe-area-inset-left);
  right: env(safe-area-inset-right);
  width: auto;
  display: flex;
  gap: 0;
  overflow: hidden;
  contain: layout paint style;
}
.tile {
  display: block;
  min-width: 0;
  height: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  background: #1a1a1a;
  overflow: hidden;
  cursor: zoom-in;
  text-decoration: none;
  position: relative;
}
.tile:focus-visible {
  outline: 3px solid CanvasText;
  outline-offset: -3px;
}
.tile.image-loading::before {
  content: "Loading image\2026";
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: .75rem;
  background: #1a1a1a;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
  pointer-events: none;
}
.tile.load-error::after {
  content: "Tap to retry";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: .75rem;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .85rem;
  text-align: center;
  pointer-events: none;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #1a1a1a;
  opacity: 0;
}
.tile.image-loaded img {
  opacity: 1;
}
#empty {
  display: none;
  padding: 2rem 1rem;
  color: var(--muted);
}
#client-diagnostics {
  position: fixed;
  left: max(.5rem, env(safe-area-inset-left));
  bottom: max(.5rem, env(safe-area-inset-bottom));
  z-index: 1000;
  margin: 0;
  padding: .5rem .6rem;
  max-width: calc(100vw - 1rem);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: .4rem;
  background: rgba(0, 0, 0, .78);
  color: #eee;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
  user-select: text;
  -webkit-user-select: text;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#lightbox {
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  width: 100vw;
  width: 100dvw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.96);
  color: white;
  isolation: isolate;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#lightbox::backdrop { background: rgba(0, 0, 0, 0.96); }
#lightbox-shell {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}
#lightbox-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding:
    max(.5rem, env(safe-area-inset-top))
    max(.5rem, env(safe-area-inset-right))
    max(.5rem, env(safe-area-inset-bottom))
    max(.5rem, env(safe-area-inset-left));
  cursor: default;
  touch-action: none;
  overscroll-behavior: contain;
}
#lightbox-image {
  position: relative;
  z-index: 0;
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: zoom-in;
}
#lightbox-image.zoomed { cursor: grab; }
#lightbox-image.dragging { cursor: grabbing; }
#lightbox-caption {
  padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
  min-height: 2rem;
  text-align: center;
  font-size: .875rem;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  z-index: 20;
  width: 3rem;
  height: 5rem;
  border: 0;
  border-radius: .35rem;
  background: rgba(0,0,0,.35);
  color: white;
  font: 2rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.nav:hover, .nav:focus-visible { background: rgba(0,0,0,.65); }
#prev { left: .5rem; }
#next { right: .5rem; }
#close {
  position: absolute;
  top: max(.5rem, env(safe-area-inset-top));
  right: max(.5rem, env(safe-area-inset-right));
  z-index: 30;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  color: white;
  font: 1.6rem/1 system-ui, sans-serif;
  cursor: pointer;
}
@media (max-width: 32rem) {
  #meta {
    flex-wrap: nowrap;
  }
  #topnav {
    min-width: 0;
  }
  #children-panel {
    width: calc(100vw - 2rem);
  }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}