:root {
  --bg: #ffffff;
  --fg: #141414;
  --muted: #737373;
  --line: #e5e5e5;
  --tile: #f2f2f2;
  --field: #ffffff;
  --danger: #c4302b;
  --row-height: 300px;
  --gap: 6px;
  --pad: clamp(16px, 4vw, 48px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0e;
    --fg: #f2f2f2;
    --muted: #9a9a9a;
    --line: #2a2a2a;
    --tile: #1a1a1a;
    --field: #161616;
    --danger: #ff6b61;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

/* Header ----------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: max(28px, env(safe-area-inset-top)) var(--pad) 8px;
}

.site-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-decoration: none;
}

.nav-link {
  background: none;
  border: 0;
  padding: 4px 0;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.nav-link:hover { color: var(--fg); }

/* Page ------------------------------------------------------------------- */

main {
  padding: 24px var(--pad) 80px;
  transition: opacity 0.15s;
}
main.is-loading { opacity: 0.5; }

.page-head {
  margin: 8px 0 32px;
  max-width: 72ch;
}

.crumbs {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.crumbs a, .section-title a { text-decoration: none; }
.crumbs a:hover, .section-title a:hover { color: var(--fg); }
.sep { margin: 0 0.45em; opacity: 0.6; }

h1 {
  font-size: clamp(26px, 3.4vw, 40px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin: 0 0 10px;
}

.description {
  margin: 0;
  color: var(--muted);
  white-space: pre-line;
}

.placeholder { color: var(--muted); font-style: italic; font-weight: 400; }

.empty, .message {
  color: var(--muted);
  padding: 64px 0;
}
.message a { color: var(--fg); }

/* Collection cards ------------------------------------------------------- */

.collections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px 16px;
  margin-bottom: 56px;
}

.card { display: block; text-decoration: none; }

.card-cover {
  aspect-ratio: 4 / 3;
  background: var(--tile);
  overflow: hidden;
}
.card-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease, opacity 0.2s;
}
.card:hover .card-cover img { transform: scale(1.025); }

.card-title {
  margin-top: 10px;
  font-weight: 500;
  font-size: 15px;
  line-height: 1.3;
}
.card-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Photo grid (justified rows that keep each photo's shape) --------------- */

.section + .section { margin-top: 48px; }

.section-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 14px;
}

/* Tiles are positioned by layoutGrid() in app.js. */
.grid {
  position: relative;
}

.tile {
  position: absolute;
  display: block;
  overflow: hidden;
  background: var(--tile);
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.2s;
}
.tile:hover img { opacity: 0.88; }

@media (max-width: 1100px) { :root { --row-height: 240px; } }
@media (max-width: 640px) {
  :root { --row-height: 140px; --gap: 4px; }
  .collections { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 10px; margin-bottom: 40px; }
  .card-title { font-size: 14px; }
}

/* Admin toolbar ---------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn-primary:hover { opacity: 0.88; border-color: var(--fg); }
.btn-danger { color: var(--danger); border-color: transparent; padding-left: 0; }
.btn-danger:hover { border-color: transparent; text-decoration: underline; }

/* Dialogs ---------------------------------------------------------------- */

.dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.form { padding: 22px; display: grid; gap: 14px; }
.form-title { margin: 0 0 4px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 500; }
.optional { font-weight: 400; color: var(--muted); margin-left: 6px; }

.field input, .field textarea, .field select {
  font: inherit;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--fg);
  border-radius: 8px;
  padding: 9px 11px;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid color-mix(in srgb, var(--fg) 35%, transparent);
  outline-offset: 0;
  border-color: var(--muted);
}

.form-error { margin: 0; color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }

.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

/* Lightbox --------------------------------------------------------------- */

body.lightbox-open { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  background: #0b0b0b;
  color: #eaeaea;
  animation: fade-in 0.15s ease;
}
.lightbox.is-fullscreen, .lightbox.immersive { background: #000; }
.lightbox.idle { cursor: none; }

.lb-main {
  position: relative;
  flex: 1;
  min-width: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  padding: 60px 80px 20px;
  overflow: hidden;
}
.lightbox.immersive .lb-main, .lightbox.is-fullscreen .lb-main { padding: 0; }

.lb-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none; /* gestures are handled in app.js */
}

.lb-img {
  display: block;
  flex: none;
  max-width: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  transform-origin: center;
  will-change: transform;
  cursor: zoom-in;
}
.lb-img.animating { transition: transform 0.22s ease; }
.lightbox.zoomed .lb-img { cursor: grab; }
.lightbox.zoomed .lb-img:active { cursor: grabbing; }
.lightbox.idle .lb-img { cursor: none; }

/* Top bar: counter on the left, details / full screen / close on the right. */
.lb-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(6px, env(safe-area-inset-top)) 6px 0 22px;
  pointer-events: none;
}
.lb-topbar > * { pointer-events: auto; }
.lb-tools { display: flex; }
.lb-counter { font-size: 12px; color: #8a8a8a; font-variant-numeric: tabular-nums; }

.lb-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  padding: 0;
  background: none;
  color: #fff;
  opacity: 0.7;
  cursor: pointer;
}
.lb-button:hover, .lb-button:focus-visible { opacity: 1; }
.lb-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.lightbox.info-open .lb-info-toggle { opacity: 1; color: #fff; }
.lb-fullscreen .icon-exit,
.lightbox.is-fullscreen .lb-fullscreen .icon-enter,
.lightbox.immersive .lb-fullscreen .icon-enter { display: none; }
.lightbox.is-fullscreen .lb-fullscreen .icon-exit,
.lightbox.immersive .lb-fullscreen .icon-exit { display: block; }

.lb-prev, .lb-next {
  position: absolute;
  top: 50%;
  z-index: 2;
  transform: translateY(-50%);
}
.lb-prev svg, .lb-next svg { width: 30px; height: 30px; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }

/* Photo-only mode and idle full screen hide the controls; moving the mouse
   ("peek") brings them back for a moment. */
.lb-topbar, .lb-prev, .lb-next { transition: opacity 0.2s; }
.lightbox.immersive:not(.peek) .lb-topbar,
.lightbox.immersive:not(.peek) .lb-prev,
.lightbox.immersive:not(.peek) .lb-next,
.lightbox.idle .lb-topbar, .lightbox.idle .lb-prev, .lightbox.idle .lb-next {
  opacity: 0;
  pointer-events: none;
}
.lightbox.immersive:not(.peek) .lb-topbar *, .lightbox.idle .lb-topbar * { pointer-events: none; }

.lb-caption {
  flex: none;
  width: 100%;
  max-width: 72ch;
  margin: 0 auto;
  padding-top: 16px;
  text-align: center;
  font-size: 14px;
}
.lb-caption:empty { display: none; }
.lightbox.immersive .lb-caption, .lightbox.is-fullscreen .lb-caption { display: none; }
.lb-title { font-size: 16px; font-weight: 500; color: #fff; }
.lb-description { margin: 4px 0 0; color: #b5b5b5; white-space: pre-line; }
.lb-where { display: inline-block; margin-top: 6px; font-size: 13px; color: #8a8a8a; text-decoration: none; }
.lb-where:hover { color: #fff; }

.lb-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 12px;
  font-size: 13px;
}
.lb-actions button, .lb-actions a {
  background: none;
  border: 0;
  padding: 2px 0;
  color: #b5b5b5;
  cursor: pointer;
  text-decoration: none;
}
.lb-actions button:hover, .lb-actions a:hover { color: #fff; }
.lb-actions .danger { color: #ff7a70; }

/* Details panel: a side panel on wide screens, a bottom sheet on phones. */
.lb-info {
  flex: none;
  width: 340px;
  overflow-y: auto;
  padding: 18px 22px 28px;
  background: #141414;
  border-left: 1px solid #262626;
  font-size: 14px;
}
.lb-info-head { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px 10px 0; }
.lb-info-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #8a8a8a; }
.lb-info-close { width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: none; color: #b5b5b5; cursor: pointer; }
.lb-info-close:hover { color: #fff; }
.lb-info-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.lb-info-title { font-size: 17px; font-weight: 500; color: #fff; }
.lb-info-description { margin: 6px 0 0; color: #b5b5b5; white-space: pre-line; }
.lb-info dl { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; margin: 18px 0 0; }
.lb-info dt { color: #8a8a8a; }
.lb-info dd { margin: 0; color: #eaeaea; overflow-wrap: anywhere; }
.lb-info dd a { color: inherit; }

@media (max-width: 640px) {
  .lb-main { padding: max(56px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom)); }
  .lb-caption { padding: 12px 16px 0; }
  .lb-prev, .lb-next { display: none; }
}

@media (max-width: 900px) {
  .lb-info {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    width: auto;
    max-height: 65%;
    border-left: 0;
    border-top: 1px solid #262626;
    border-radius: 16px 16px 0 0;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    animation: slide-up 0.22s ease;
  }
}

@keyframes slide-up { from { transform: translateY(100%); } }

/* Upload progress, drop target, toasts ----------------------------------- */

.uploads {
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 40;
  width: min(320px, calc(100vw - 40px));
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  display: grid;
  gap: 10px;
}
.uploads-bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.uploads-bar span { display: block; height: 100%; background: var(--fg); transition: width 0.2s; }
.uploads-errors { margin: 0; padding-left: 18px; color: var(--danger); font-size: 13px; max-height: 120px; overflow: auto; }
.uploads .btn { justify-self: start; }

.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 60;
  display: grid;
  place-items: center;
  border: 2px dashed var(--muted);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  pointer-events: none;
}
.drop-label { font-size: 18px; font-weight: 500; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 70;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  animation: fade-in 0.2s ease;
  transition: opacity 0.3s;
}
.toast-out { opacity: 0; }

@keyframes fade-in { from { opacity: 0; } }

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