:root {
  --fx: 50%;
  --fy: 50%;
  --dock-pad: calc(12px + env(safe-area-inset-right, 0px));
  --dock-bot: calc(10px + env(safe-area-inset-bottom, 0px));
  --fg: #f4f1ea;
  --fg-dim: rgba(244, 241, 234, 0.72);
  --glass: rgba(8, 8, 8, 0.42);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #f4f1ea;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { background: #000; color: var(--fg); }
body.viewer {
  font: 13px/1.35 "Inter", "Noto Sans", ui-sans-serif, system-ui, sans-serif;
  overflow: hidden;
  min-height: 100dvh;
  background: #000;
  user-select: none;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.stage {
  position: fixed;
  inset: 0;
  background: #000;
  touch-action: none;
}
.stage figure {
  position: absolute;
  inset: 0;
  margin: 0;
}
.stage picture, .stage img#photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.stage img#photo {
  object-fit: cover;
  object-position: var(--fx) var(--fy);
  background: #000;
}
body.viewer .stage.fit-contain:not(.fit-js) img#photo {
  object-fit: contain;
}
body.viewer .stage.fit-cover-x:not(.fit-js) img#photo {
  width: auto;
  height: 100%;
  max-width: none;
  top: 0;
  bottom: 0;
  right: auto;
  left: var(--fx);
  object-fit: fill;
  transform: translateX(-50%);
}
body.viewer .stage.fit-cover-y:not(.fit-js) img#photo {
  width: 100%;
  height: auto;
  max-height: none;
  left: 0;
  right: 0;
  bottom: auto;
  top: var(--fy);
  object-fit: fill;
  transform: translateY(-50%);
}
body.viewer .stage.fit-js picture {
  display: contents;
}
body.viewer .stage.fit-js img#photo,
body.viewer .stage.fit-js img#photo-hi,
body.viewer .stage.fit-js img#photo-out {
  object-fit: fill !important;
  max-width: none !important;
  max-height: none !important;
  position: fixed !important;
  transform-origin: 0 0 !important;
  left: 0;
  top: 0;
  user-select: none;
  pointer-events: none;
}
body.viewer .stage.fit-js img#photo {
  z-index: 1;
  opacity: 1;
  transition: opacity .45s var(--ease);
}
img#photo-hi {
  opacity: 0;
  z-index: 3;
  pointer-events: none;
}
img#photo-hi.on {
  opacity: 1;
  transition: opacity .35s var(--ease);
}
img#photo-out {
  z-index: 4;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s var(--ease);
}
img#photo-out.show {
  opacity: 1;
}
.spinner {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  top: calc(16px + env(safe-area-inset-top, 0px));
  z-index: 9;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  color: #eee;
  margin: 0;
}
.chk span { color: #888; font-size: 12px; }
.chk input { width: auto; accent-color: #ddd; }
.sliders label { margin-top: 10px; }
.sliders input[type=range] { width: 100%; }
.fit-previews {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.fit-previews figure { margin: 0; }
.fit-previews figcaption {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 6px;
}
.fit-previews .vp {
  position: relative;
  width: 100%;
  aspect-ratio: var(--vp, 1);
  overflow: hidden;
  background: #000;
  border-radius: 6px;
  border: 1px solid #2a2a2a;
}
.fit-previews figure[data-vp="9/16"] .vp { aspect-ratio: 9/16; }
.fit-previews figure[data-vp="1/1"] .vp { aspect-ratio: 1/1; }
.fit-previews figure[data-vp="16/9"] .vp { aspect-ratio: 16/9; }
.fit-previews figure[data-vp="21/9"] .vp { aspect-ratio: 21/9; }
.fit-previews .vp img {
  position: absolute;
  display: block;
  max-width: none;
}
@media (max-width: 820px) {
  .fit-previews { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.hit {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 18vw;
  max-width: 160px;
  z-index: 6;
  text-decoration: none;
  color: var(--fg);
  display: flex;
  align-items: center;
  pointer-events: auto;
}
.hit-prev { left: 0; justify-content: flex-start; padding-left: calc(10px + env(safe-area-inset-left, 0px)); }
.hit-next { right: 0; justify-content: flex-end; padding-right: calc(10px + env(safe-area-inset-right, 0px)); }
.hit:focus-visible { outline: none; }
.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.2);
  opacity: 0;
  transform: scale(.96);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: none;
}
.nav-btn svg { width: 20px; height: 20px; display: block; }
body.viewer.show-ui:not(.playing) .nav-btn,
body.viewer:not(.has-js) .nav-btn {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
body.viewer.has-js:not(.show-ui) .hit,
body.viewer.playing .hit {
  pointer-events: none;
}

.rail {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 7;
  width: 88px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 10px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  background: linear-gradient(90deg, rgba(0,0,0,.55), rgba(0,0,0,.12) 70%, transparent);
  transform: translateX(-110%);
  transition: transform .35s var(--ease);
  pointer-events: none;
}
.rail { scrollbar-width: none; }
body.viewer:not(.has-js) .rail,
body.viewer.show-ui:not(.playing) .rail {
  transform: none;
  pointer-events: auto;
}
.rail-item {
  display: block;
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid transparent;
  opacity: .72;
}
.rail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.rail-item.on {
  opacity: 1;
  border-color: rgba(255,255,255,.85);
  box-shadow: 0 0 0 1px rgba(0,0,0,.5);
}
.rail-item:hover { opacity: 1; }

body.viewer.zoomed { cursor: grab; }
body.viewer.zoomed.panning { cursor: grabbing; }

.dock {
  position: fixed;
  right: var(--dock-pad);
  bottom: var(--dock-bot);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease);
}
body.viewer.show-ui:not(.playing) .dock,
body.viewer:not(.has-js) .dock,
.dock:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.dock a, .dock button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--fg);
  text-decoration: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.dock a:hover, .dock button:hover,
.dock a:focus-visible, .dock button:focus-visible {
  background: rgba(255,255,255,.12);
  outline: none;
}
.dock svg { width: 15px; height: 15px; display: block; }
.dock .count {
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  padding: 0 8px 0 6px;
  font-size: 11px;
}
.dock .cats {
  display: flex;
  gap: 2px;
  padding: 0 4px;
  max-width: 36vw;
  overflow: hidden;
}
.dock .cats a {
  width: auto;
  padding: 0 8px;
  height: 26px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.dock .cats a.on, .dock .cats a[aria-current="page"] {
  color: var(--fg);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: var(--glass);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  z-index: 12;
  transition: opacity .3s, transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Admin is allowed to look like a tool, not the public gallery */
body.admin {
  font: 15px/1.45 "Inter", ui-sans-serif, system-ui, sans-serif;
  background: #111;
  color: #eee;
  overflow: auto;
  user-select: text;
  min-height: 100dvh;
}
.admin-wrap { max-width: 980px; margin: 0 auto; padding: 28px 20px 80px; }
.admin-wrap h1 { font-weight: 560; letter-spacing: -.02em; font-size: 22px; margin: 0 0 18px; }
.admin-wrap a { color: #ddd; }
.grid { display: grid; gap: 16px; }
label { display: block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: #aaa; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  background: #1c1c1c;
  color: #f2f2f2;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 280px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: #f2f2f2; color: #111; border: 0; border-radius: 8px;
  padding: 10px 16px; font: inherit; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: transparent; color: #ddd; border: 1px solid #444; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card { background: #181818; border: 1px solid #2a2a2a; border-radius: 12px; padding: 16px; }
.thumb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.thumb-list a { color: inherit; text-decoration: none; }
.thumb-list img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.focal-wrap { position: relative; cursor: crosshair; max-height: 70vh; overflow: hidden; border-radius: 8px; background: #000; }
.focal-wrap img { width: 100%; height: auto; display: block; max-height: 70vh; object-fit: contain; }
.focal-mark {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

@media (max-width: 720px) {
  .hit { width: 20vw; max-width: none; }
  .dock .cats { display: none; }
  .rail { width: 84px; }
  .rail-item { width: 64px; height: 64px; }
  .nav-btn { width: 48px; height: 48px; }
}
@media (pointer: coarse) {
  .nav-btn { width: 52px; height: 52px; }
  .dock a, .dock button { width: 40px; height: 40px; }
  body.viewer.show-ui:not(.playing) .dock { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
