:root {
  --bg: #111;
  --fg: #eee;
  --muted: #999;
  --tile: #222;
  --accent: #6cf;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.4 system-ui, -apple-system, sans-serif; -webkit-tap-highlight-color: transparent; }
body.viewing { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; }

header {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 14px; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: rgba(17, 17, 17, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
header .brand { font-weight: 600; }
header nav { display: flex; gap: 14px; flex: 1; white-space: nowrap; }
header nav a { color: var(--muted); padding: 4px 0; }
header nav a.active { color: var(--fg); }
header select, header button { background: var(--tile); color: var(--fg); border: 0; border-radius: 6px; padding: 5px 8px; min-height: 32px; }
@media (max-width: 480px) { header .brand { display: none; } }

main { padding: 0 max(2px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-left)); }
h2 { font-size: 20px; margin: 16px 10px 6px; }
h2 .count { color: var(--muted); font-size: 13px; font-weight: normal; margin-left: 8px; }
.crumbs { margin: 12px 10px 0; color: var(--muted); font-size: 13px; }
.crumbs a { color: var(--accent); }
.status { color: var(--muted); padding: 40px 10px; text-align: center; }
.status button { background: var(--tile); color: var(--fg); border: 0; border-radius: 6px; padding: 6px 12px; }

.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 8px; padding: 6px 8px 14px; }
.albums a img, .albums a .ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--tile); display: block; }
.albums a .name { margin-top: 5px; font-size: 14px; overflow-wrap: anywhere; }
.albums a .count { color: var(--muted); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px; }
.grid h3 { grid-column: 1 / -1; margin: 18px 10px 6px; font-size: 15px; font-weight: 600; }
.grid h3:first-child { margin-top: 4px; }
.grid a { position: relative; aspect-ratio: 1; background: var(--tile); overflow: hidden; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .badge { position: absolute; right: 5px; bottom: 3px; font-size: 12px; text-shadow: 0 0 3px #000; }
.grid .video-ph { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 28px; color: var(--muted); }
.sentinel { height: 1px; }

#login { max-width: 300px; margin: 18vh auto; display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
#login h1 { font-weight: 600; text-align: center; }
#login input, #login button { padding: 12px; border-radius: 8px; border: 1px solid #333; background: var(--tile); color: var(--fg); font-size: 16px; }
#login button { background: var(--accent); color: #000; border: 0; font-weight: 600; }
#login .error { color: #f77; text-align: center; }
body.login header, body.login main { display: none; }

#viewer { position: fixed; inset: 0; z-index: 10; background: #000; touch-action: manipulation; } /* pinch and pan, no double-tap zoom */
#viewer .stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#viewer img, #viewer video { max-width: 100%; max-height: 100%; user-select: none; -webkit-user-select: none; }
#viewer .caption {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 3px;
  padding: 28px max(16px, env(safe-area-inset-left)) calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .75)); font-size: 13px; pointer-events: none;
}
#viewer .caption .when { font-size: 15px; }
#viewer .caption .links { display: flex; gap: 16px; }
#viewer .caption a { color: var(--accent); pointer-events: auto; }
#viewer button { position: absolute; background: none; border: 0; color: #fff; font-size: 34px; padding: 8px 16px; opacity: .85; text-shadow: 0 0 6px #000; }
#viewer .close { top: env(safe-area-inset-top); right: env(safe-area-inset-right); }
#viewer .prev { left: 0; top: 50%; transform: translateY(-50%); }
#viewer .next { right: 0; top: 50%; transform: translateY(-50%); }
#viewer.bare .caption, #viewer.bare button { display: none; }
/* Phones turn pages by tapping the sides; a video takes the taps itself, so it keeps the buttons. */
@media (hover: none) { #viewer:not(.video) .prev, #viewer:not(.video) .next { display: none; } }
