:root {
  color-scheme: dark;
  --bg: #0a0b0e;
  --bg-2: #111318;
  --panel: #14161c;
  --panel-hi: #1b1e26;
  --border: #242832;
  --border-hi: #343a47;
  --text: #e9ecf1;
  --muted: #8a92a0;
  --muted-2: #5a6270;
  --accent: #7aa7ff;
  --accent-hi: #9bbcff;
  --danger: #ff6b6b;
  --ok: #5cdb8a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #151823 0%, var(--bg) 60%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  /* Disable iOS double-tap-to-zoom globally while keeping pinch-zoom on media. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hi); }

button { font-family: inherit; }

/* ============ top bar ============ */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.8rem 1.5rem;
  background: rgba(10, 11, 14, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  font-size: 1.05rem;
}
.brand-mark { font-size: 1.15rem; filter: drop-shadow(0 0 6px rgba(122, 167, 255, 0.4)); }
.brand-name { opacity: 0.95; }

#breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
  flex: 1 1 auto;
  min-width: 0;
}
#breadcrumb a { color: var(--muted); transition: color 0.15s; }
#breadcrumb a:hover { color: var(--text); }
#breadcrumb .sep { color: var(--muted-2); }
#breadcrumb .current {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}

.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.counts {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.sort-wrap { display: inline-flex; align-items: center; }
.sort {
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 2rem 0.4rem 0.85rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.15s, background-color 0.15s;
}
.sort:hover { border-color: var(--border-hi); }
.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ grid ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

.card {
  position: relative;
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  color: inherit;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hi);
  box-shadow: var(--shadow);
}

.thumb {
  aspect-ratio: 1 / 1;
  width: 100%;
  background: linear-gradient(135deg, var(--panel-hi) 0%, var(--bg-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.thumb img,
.thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.card:hover .thumb img,
.card:hover .thumb video { transform: scale(1.04); }

.thumb .placeholder {
  color: var(--muted-2);
  font-size: 2.5rem;
  opacity: 0.7;
}

/* Skeleton loaders — shown while /api/list is in flight. Placeholders mirror
 * the real card layout so the viewport doesn't jump when content arrives. */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--panel-hi);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: skeleton-shimmer 2.4s linear infinite;
}
@keyframes skeleton-shimmer {
  100% { transform: translateX(100%); }
}
.card.skeleton-card { cursor: default; pointer-events: none; }
.card.skeleton-card:hover { transform: none; border-color: var(--border); box-shadow: none; }
.skeleton-line {
  height: 0.85rem;
  width: 70%;
  border-radius: 4px;
  background: var(--panel-hi);
  position: relative;
  overflow: hidden;
}
.skeleton-line::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.06) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: skeleton-shimmer 2.4s linear infinite;
}
.skeleton-line.short { width: 40%; }

.label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  font-size: 0.88rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.label .icon {
  flex: 0 0 auto;
  font-size: 0.9rem;
  opacity: 0.7;
}
.label .name {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}
.label .meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.8rem 0.55rem;
  font-size: 0.73rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  background: var(--panel);
  margin-top: -1px;
}
.meta-row .date {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}
.meta-row .gps-pin {
  flex: 0 0 auto;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
}
.meta-row .gps-pin:hover { color: var(--accent-hi); }
.meta-row .dim { flex: 0 0 auto; opacity: 0.8; }
.meta-row.empty { display: none; }

.viewer-meta {
  display: flex;
  gap: 0 0.75rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.viewer-meta > * { white-space: nowrap; }
.viewer-meta a { color: var(--accent); }

.badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.68rem;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: #fff;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .play-overlay { opacity: 1; }
.play-overlay::after {
  content: "▶";
  color: #fff;
  font-size: 2.5rem;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

.card-actions {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.3rem;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}
/* The label below the thumb would visually sit over the download icon —
 * nudge the thumb bottom a bit so the icon floats clear of the label. */
.card:hover .card-actions { opacity: 1; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--accent-hi);
}
/* Loading state for the card download button: shows a small spinner so
   the user gets immediate feedback while the file is being fetched. */
.icon-btn.loading { pointer-events: none; }
.icon-btn.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: icon-btn-spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes icon-btn-spin { to { transform: rotate(360deg); } }

.empty {
  color: var(--muted);
  padding: 4rem 2rem;
  text-align: center;
  grid-column: 1 / -1;
  font-size: 0.95rem;
}
.empty .empty-icon {
  font-size: 3rem;
  opacity: 0.3;
  display: block;
  margin-bottom: 1rem;
}

/* ============ viewer ============ */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.96);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  z-index: 100;
  animation: fade-in 0.15s ease;
}
.viewer.hidden { display: none; }

/* Lock body scroll while the viewer is open. */
body.viewer-open {
  overflow: hidden;
  touch-action: none;
}

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

.viewer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 11, 14, 0.6);
  gap: 1rem;
}
.viewer-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1 1 auto;
}
.viewer-title {
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.viewer-top-actions {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.viewer-content {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  min-height: 0;
  /* Keep zoomed / panned content from spilling over the header + cropper. */
  overflow: hidden;
  position: relative;
}
.viewer-content img,
.viewer-content video {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: #000;
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Video wrapper — fills the available viewer space; the <video> inside
 * letter-boxes via object-fit so the wrap size is stable whether or not
 * metadata has loaded yet. */
.video-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.video-wrap video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

/* Opaque backdrop — fully covers the poster + Chrome's native circular
 * throbber that otherwise bleeds through the old translucent gradient
 * and stacks visually with our ring. */
.video-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  background: #000;
  color: #fff;
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 2;
  letter-spacing: 0.02em;
}
.video-status.hidden { display: none; }

.video-ring-wrap {
  position: relative;
  width: 92px;
  height: 92px;
}
/* The spinner div is the rotation target; the label (a sibling) stays
 * upright so the "%" text doesn't tumble. Animation is gated on the
 * .indeterminate class so determinate % doesn't drift around the ring. */
.video-ring-spinner {
  position: absolute;
  inset: 0;
}
.video-status.indeterminate .video-ring-spinner {
  animation: video-ring-spin 1.2s linear infinite;
}
/* -90deg so dasharray starts at 12 o'clock and grows clockwise. */
.video-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.video-ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 6;
}
.video-ring-fill {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dasharray 0.45s ease-out;
}
@keyframes video-ring-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.video-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.05rem;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.video-status.indeterminate .video-ring-label { display: none; }

.video-status-text {
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  max-width: min(80%, 360px);
  text-align: center;
}
.video-status.level-warn .video-status-text { color: #ffd28a; }
.video-status.level-error .video-status-text { color: #ff9b9b; }
/* Level tint overrides the gradient stroke for warn/error states. */
.video-status.level-warn .video-ring-fill { stroke: #ffd28a; }
.video-status.level-error .video-ring-fill { stroke: #ff9b9b; }
.video-status.level-error .video-ring-spinner { animation: none; }

/* Wrapper for an image that can host a crop-selection overlay.
 * aspect-ratio is set via JS once the image loads so the wrap shrinks
 * correctly inside the flex viewer-content without exceeding its bounds. */
.crop-wrap {
  position: relative;
  display: block;
  max-width: 100%;
  max-height: 100%;
  line-height: 0;
  /* Fallback until JS sets an explicit aspect-ratio. */
  width: fit-content;
  height: fit-content;
  margin: auto;
}
.crop-wrap img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.crop-wrap.selecting img { cursor: crosshair; }
.crop-wrap.zoomed { cursor: grab; }
.crop-wrap.zoomed.panning { cursor: grabbing; }
.crop-wrap {
  transform-origin: center center;
  will-change: transform;
  transition: none;
  touch-action: none;
}
/* Canvas painter: paints the image at the current zoom/pan by sampling from
 * the full-resolution bitmap. No CSS transform on the wrap — the canvas IS
 * the transformed view, so we get pixel-perfect zoom up to natural res. */
.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.crop-canvas {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* Controls visibility: hide crop outputs until the user is actively cropping. */
#image-cropper .crop-only { display: none; }
#image-cropper.cropping .crop-only { display: inline-flex; }

.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, 0);
  transition: box-shadow 0.1s;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.crop-mask.active {
  box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, 0.55);
}
.crop-selection {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  /* Cut the mask out of the selected rectangle. */
  background: transparent;
  outline: 1px dashed rgba(255, 255, 255, 0.6);
  outline-offset: -2px;
  pointer-events: none;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  width: 48px;
  height: 48px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  z-index: 5;
}
.viewer-nav svg { display: block; }
.viewer-nav:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}
.viewer-nav.prev { left: 1rem; }
.viewer-nav.next { right: 1rem; }

/* ============ buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
  font-weight: 500;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
}
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn[disabled]:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-primary {
  background: linear-gradient(180deg, #6a93f2 0%, #4a78e0 100%);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(180deg, #7aa3ff 0%, #5a88f0 100%);
  border-color: rgba(255, 255, 255, 0.3);
}
.btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.1);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }

.btn-icon {
  font-weight: 700;
  font-size: 1em;
  line-height: 1;
}
.btn.icon-only {
  width: 36px;
  padding: 0.45rem 0;
  justify-content: center;
  font-size: 1rem;
}

/* Viewer close button — prominent and always visible. */
#viewer-close {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  font-weight: 600;
}
#viewer-close:hover {
  background: rgba(255, 107, 107, 0.2);
  border-color: rgba(255, 107, 107, 0.55);
  color: #ff9b9b;
}
.btn.hidden { display: none; }
.btn[aria-pressed="true"] {
  background: rgba(122, 167, 255, 0.18);
  border-color: rgba(122, 167, 255, 0.55);
  color: var(--accent-hi);
}
.btn.starred { color: #ffd668; }
.btn.starred svg { fill: currentColor; }
.btn svg { display: block; }

.top-link { text-decoration: none; color: var(--text); }

/* --- desktop: menu items inline in the top bar; mobile button hidden --- */
.menu-items {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.only-mobile { display: none; }

/* ----- star button overlays on cards ----- */
.card-star {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  cursor: pointer;
  z-index: 2;
  backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s, transform 0.15s;
  opacity: 0;
}
.card:hover .card-star { opacity: 1; }
.card-star.starred { opacity: 1; color: #ffd668; background: rgba(0, 0, 0, 0.7); }
.card-star svg { display: block; }
.card-star.starred svg { fill: currentColor; }
.card-star:hover { transform: scale(1.08); }
.card-star:active { transform: scale(0.94); }
@media (hover: none) {
  .card-star { opacity: 1; }
}

/* Badge is now below the star so they don't collide */
.thumb .badge { top: 0.4rem; left: 0.4rem; right: auto; }

/* ----- admin-only hide button (shown only on cards in admin mode) ----- */
.card-hide {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  cursor: pointer;
  z-index: 2;
  backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s, transform 0.15s;
  opacity: 0;
  padding: 0;
  line-height: 1;
}
.card:hover .card-hide { opacity: 1; }
.card-hide.is-hidden { opacity: 1; color: #e66; background: rgba(0, 0, 0, 0.7); }
.card-hide:hover { transform: scale(1.08); }
.card-hide:active { transform: scale(0.94); }
@media (hover: none) {
  .card-hide { opacity: 1; }
}

/* Card styling when admin has hidden the item: still visible to admin but
   visually muted so admins can see what's been taken off the public view. */
.card.admin-hidden .thumb,
.card.admin-hidden .label,
.card.admin-hidden .meta-row {
  opacity: 0.45;
  filter: grayscale(0.55);
}
.card.admin-hidden::after {
  content: "HIDDEN";
  position: absolute;
  bottom: 0.4rem;
  left: 0.4rem;
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  background: rgba(230, 80, 80, 0.85);
  color: #fff;
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
}
/* Badge offset when hide button is present (badge was at left, push down) */
body.is-admin .thumb .badge { top: 3rem; }

/* ----- viewer info panel (EXIF) ----- */
.viewer-info-panel {
  position: absolute;
  top: 60px;
  right: 1rem;
  width: 280px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  background: rgba(15, 17, 22, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  padding: 0.9rem 1rem;
  font-size: 0.82rem;
  line-height: 1.5;
  z-index: 6;
}
.viewer-info-panel.hidden { display: none; }
.viewer-info-panel h4 {
  margin: 0.4rem 0 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.viewer-info-panel h4:first-child { margin-top: 0; }
.viewer-info-panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0;
}
.viewer-info-panel dt { color: var(--muted); font-weight: normal; }
.viewer-info-panel dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.viewer-info-panel a { color: var(--accent); }

/* ============ cropper ============ */
.cropper {
  border-top: 1px solid var(--border);
  background: rgba(10, 11, 14, 0.7);
  padding: 0.9rem 1.25rem;
}
.cropper.hidden { display: none; }

.cropper-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  justify-content: space-between;
}

.cropper-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.cropper-label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 0.25rem;
}

.cropper-val {
  display: inline-block;
  min-width: 68px;
  text-align: center;
  padding: 0.25rem 0.6rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

/* Button-label variants: full text on desktop, short on mobile via media query. */
.lbl-short { display: none; }

.cropper-input {
  width: 84px;
  padding: 0.3rem 0.55rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  transition: border-color 0.15s;
}
.cropper-input:hover { border-color: var(--border-hi); }
.cropper-input:focus { outline: none; border-color: var(--accent); }
.cropper-input.invalid { border-color: var(--danger); }
.cropper-sep { color: var(--muted-2); font-size: 0.8rem; }

.cropper-duration {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cropper-duration.hidden { display: none; }

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}
.checkbox input { margin: 0; accent-color: var(--accent); }
.checkbox:hover { color: var(--text); }

.cropper-status {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.1em;
}
.cropper-status.error { color: var(--danger); }
.cropper-status.ok { color: var(--ok); }

/* ============ safe areas (notches, home indicators) ============ */
.top {
  padding-top: max(0.8rem, env(safe-area-inset-top));
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}
.grid {
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}
.viewer-top {
  padding-top: max(0.9rem, env(safe-area-inset-top));
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}
.cropper {
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  padding-bottom: max(0.9rem, env(safe-area-inset-bottom));
}

/* Enable native pinch-to-zoom on images in the viewer. */
.viewer-content img {
  touch-action: pinch-zoom;
}

/* ============ mobile / touch ============ */
@media (max-width: 720px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 1rem;
  }
  .top {
    padding: 0.55rem 0.85rem;
    gap: 0.35rem;
    flex-wrap: nowrap;
    overflow: hidden;
  }
  .top-right {
    gap: 0.3rem;
    margin-left: auto;
    flex-shrink: 0;
  }
  /* Nav links become icon-only — hide the text label, keep the glyph. */
  .top-link .lbl-full { display: none; }
  .top-link .lbl-icon { font-size: 1rem; }
  .top-link { padding: 0.4rem 0.55rem !important; min-height: 34px; }
  .top-right .btn { padding: 0.35rem 0.5rem; min-height: 34px; }
  .top-right .btn.icon-only { width: 34px; }
  /* Compact sort dropdown */
  .sort { padding: 0.35rem 1.6rem 0.35rem 0.55rem; font-size: 0.75rem; }

  /* Mobile menu: ⋯ button shows, items collapse into a panel */
  .only-mobile { display: inline-flex; }
  #zip-folder { display: none !important; }
  .menu-items {
    display: none;
    position: absolute;
    right: 0.6rem;
    top: calc(100% + 0.25rem);
    background: rgba(15, 17, 22, 0.96);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    padding: 0.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    min-width: 160px;
    z-index: 9;
  }
  .top.menu-open { position: relative; overflow: visible; }
  .top.menu-open .menu-items { display: flex; }
  .top.menu-open .menu-items .btn,
  .top.menu-open .menu-items .top-link,
  .top.menu-open .menu-items .sort-wrap {
    width: 100%;
    justify-content: flex-start;
  }
  .top.menu-open .menu-items .lbl-full { display: inline; }
  .top.menu-open .menu-items .sort { width: 100%; }
  .brand-name { display: none; }
  #breadcrumb { font-size: 0.85rem; }
  #breadcrumb .current { max-width: 55vw; }
  .counts { display: none; }
  .viewer-top {
    padding: 0.55rem 3rem 0.55rem 0.8rem;
    gap: 0.4rem;
    flex-wrap: wrap;
    position: relative;
  }
  /* Pin the close button to the top-right corner so it never wraps away. */
  #viewer-close {
    position: absolute;
    top: 0.5rem;
    right: 0.6rem;
    z-index: 3;
  }
  .viewer-title { font-size: 0.85rem; }
  .viewer-meta {
    font-size: 0.7rem;
    gap: 0 0.5rem;
    line-height: 1.25;
  }
  /* Drop the raw file size on phones — dims + date + GPS are plenty. */
  .viewer-meta .size-mobile-hide { display: none; }
  .viewer-content { padding: 0.75rem; }
  .viewer-nav {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }
  .viewer-nav.prev { left: 0.5rem; }
  .viewer-nav.next { right: 0.5rem; }
  /* Hide nav arrows on mobile — users swipe. */
  .viewer-nav { display: none; }

  /* Touch targets ≥ 44px per platform guidelines. */
  .btn { padding: 0.55rem 0.9rem; min-height: 40px; }
  .btn-sm { padding: 0.45rem 0.75rem; min-height: 36px; }
  .icon-btn { width: 38px; height: 38px; }

  /* Card actions are permanently visible on touch devices. */
  .card-actions { opacity: 1; }
  .play-overlay { opacity: 0.9; }

  /* Cropper stacks vertically on narrow screens. */
  .cropper { padding: 0.6rem 0.75rem; }
  .cropper-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }
  .cropper-group {
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0.3rem;
  }
  .cropper-val { min-width: 58px; font-size: 0.8rem; padding: 0.2rem 0.45rem; }
  .cropper-input { width: 66px; font-size: 0.8rem; padding: 0.25rem 0.4rem; }
  .cropper-sep { font-size: 0.75rem; }
  /* Hide the "Clip"/"Zoom"/"Crop" labels — the controls speak for themselves. */
  .cropper-label { display: none; }
  /* Shorter button text on narrow screens. */
  .lbl-full { display: none; }
  .lbl-short { display: inline; }
  /* Tighter buttons so everything fits in one row. */
  .cropper-group .btn { padding: 0.35rem 0.55rem; min-height: 34px; font-size: 0.78rem; }
  .cropper-duration { font-size: 0.78rem; }
  .checkbox { font-size: 0.75rem; }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .cropper-label { display: none; }
}

/* Landscape on phones — maximise media space. */
@media (max-height: 500px) and (orientation: landscape) {
  .viewer-top { padding: 0.4rem 0.75rem; }
  .viewer-title { display: none; }
  .viewer-content { padding: 0.25rem; }
  .cropper { padding: 0.5rem 0.75rem; }
  .cropper-row { flex-direction: row; }
}

/* Devices that can't hover (touch) — always show card actions. */
@media (hover: none) {
  .card-actions { opacity: 1; }
  .card:hover .thumb img,
  .card:hover .thumb video { transform: none; }
}

/* Honour reduced motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  /* Skeleton shimmer would strobe under the 0.01ms rule above — kill the
   * sweeping gradient and replace with a gentle opacity pulse. Slow pulses
   * are considered safe under reduced-motion (unlike sliding motion). */
  .skeleton::after,
  .skeleton-line::after,
  .tl-skeleton-header::after,
  .tl-item.skeleton-item::after {
    animation: none !important;
    display: none !important;
  }
  .skeleton,
  .skeleton-line,
  .tl-skeleton-header,
  .tl-item.skeleton-item {
    animation: skeleton-pulse 2.8s ease-in-out infinite !important;
  }
}
@keyframes skeleton-pulse {
  50% { opacity: 0.55; }
}
