* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-primary);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding-top: 0;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.gallery-tile {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: 180px auto auto;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  padding: 12px;
}
/* The page's neutral contours behind the card's content; the opaque
   .thumbnail-container keeps them off the photo. Four offsets so
   neighbouring cards show different parts of the tile. */
.gallery-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--topo-line);
  opacity: var(--topo-o);
  -webkit-mask: url(/img/topo/ridge-tile.svg) 0 0 / 640px 640px repeat;
  mask: url(/img/topo/ridge-tile.svg) 0 0 / 640px 640px repeat;
}
.gallery-tile:nth-child(4n+2)::before { -webkit-mask-position: -213px -160px; mask-position: -213px -160px; }
.gallery-tile:nth-child(4n+3)::before { -webkit-mask-position: -427px -320px; mask-position: -427px -320px; }
.gallery-tile:nth-child(4n+4)::before { -webkit-mask-position: -107px -480px; mask-position: -107px -480px; }
@media print { .gallery-tile::before { display: none; } }

.thumbnail-container {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  overflow: hidden;
  cursor: pointer;
}

.tile-location-badge, .tile-link-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  color: white;
}
.tile-location-badge svg { width: 13px; height: 13px; fill: currentColor; }
.tile-location-badge--gps { background: rgba(0, 0, 0, 0.25); opacity: 0.75; }
.tile-location-badge--gps svg { fill: none; stroke: currentColor; stroke-width: 1.8; }
.tile-link-badge svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.tile-location-badge ~ .tile-link-badge { right: 36px; }

.thumbnail-track {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  height: 100%;
}

.thumbnail-track[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.thumbnail-track img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.metadata-summary {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: grid;
  gap: 4px;
}

.tile-actions {
  display: flex;
  gap: 8px;
}

.tile-actions button {
  border: 1px solid var(--border-input);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 8px 10px;
  cursor: pointer;
  font-family: var(--font-primary);
  font-size: 0.875rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.tile-actions button:hover {
  background: var(--bg-secondary);
  border-color: var(--accent-fill);
  color: var(--accent-primary);
}

.gallery-grid[hidden] {
  display: none;
}

.gallery-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.gallery-search-wrap { flex: 0 0 240px; }
.gallery-search {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}
.gallery-search:focus-visible { outline: none; border-color: var(--accent-fill); box-shadow: 0 0 0 3px var(--accent-glow); }
.gallery-search-count { margin: 4px 0 0; padding-left: 12px; font-size: 12px; color: var(--text-secondary); }

/* beta-widget.js mounts its pill here instead of the header; values match the
   planner / BaseStation toolbar pill, sized to the Grid | Map switch. */
.gallery-beta-feedback-slot { display: contents; }
.gallery-toolbar #a22-bw-pill {
  height: 32px;
  margin-left: auto;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 6px;
  border-color: var(--accent-fill);
  background: rgba(var(--accent-fill-rgb), 0.08);
  color: var(--accent-primary);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: normal;
}
.gallery-toolbar #a22-bw-pill svg { width: 11px; height: 11px; }
.gallery-toolbar #a22-bw-pill:hover { box-shadow: none; background: rgba(var(--accent-fill-rgb), 0.16); }
[data-theme="dark"] .gallery-toolbar #a22-bw-pill { background: rgba(var(--accent-fill-rgb), 0.12); color: var(--accent-fill); }

/* Same segmented switch as the planner's Map / Full plan control. */
.gallery-view-toggle {
  display: inline-flex;
  gap: 2px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-lg);
}

.gallery-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.gallery-view-btn:hover:not(.active) { color: var(--text-primary); }
.gallery-view-btn.active { background: var(--accent-light); color: var(--accent-on-tint); font-weight: 600; }
.gallery-view-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-glow); }
.gallery-view-toggle .info-pill { align-self: center; margin: 0 4px 0 2px; }
.gallery-view-btn::before {
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: var(--switch-icon) center / contain no-repeat;
  mask: var(--switch-icon) center / contain no-repeat;
}
[data-gallery-view="grid"] { --switch-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.4'%3E%3Crect x='2' y='2' width='5' height='5' rx='1'/%3E%3Crect x='9' y='2' width='5' height='5' rx='1'/%3E%3Crect x='2' y='9' width='5' height='5' rx='1'/%3E%3Crect x='9' y='9' width='5' height='5' rx='1'/%3E%3C/svg%3E"); }
[data-gallery-view="map"] { --switch-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.4' stroke-linejoin='round'%3E%3Cpath d='M1.5 3.8 5.5 2.2l5 1.8 4-1.6v9.8l-4 1.6-5-1.8-4 1.6zM5.5 2.2V12M10.5 4v9.8'/%3E%3C/svg%3E"); }
[data-gallery-view="album"] { --switch-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.4' stroke-linejoin='round' stroke-linecap='round'%3E%3Crect x='2' y='5' width='9' height='9' rx='1'/%3E%3Cpath d='M5 3a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1M2.5 12.5l3-3 2 2 1-1 2 2'/%3E%3C/svg%3E"); }

.gallery-map {
  height: calc(100dvh - var(--nav-height) - 96px);
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-primary);
}

/* Sidebar left of the main column: Timeline and Themes in Grid, Places in Album, nothing in Map;
   each browser is one .sidebar-block. It scrolls on its own, so drilling in never moves the main column.
   Card and title are the planner's .planner-section-card / .planner-section-title. */
.gallery-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.gallery-layout:has(> .gallery-sidebar[hidden]) { grid-template-columns: minmax(0, 1fr); }
/* A full-height panel like the planner's left column: blocks stack from the
   top and the ridge-tile contours fill whatever height is left below them. */
.gallery-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 16px);
  height: calc(100dvh - var(--nav-height) - 32px);
  overflow-y: auto;
  isolation: isolate;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-card);
}
.gallery-sidebar::before,
.gallery-sidebar::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.gallery-sidebar::before {
  background: var(--topo-line);
  opacity: var(--topo-art-o);
  -webkit-mask: url(/img/topo/ridge-tile.svg) 0 100% / 640px 640px repeat;
  mask: url(/img/topo/ridge-tile.svg) 0 100% / 640px 640px repeat;
}
/* The planner start view's index-line treatment: one contour of the tile, one
   copy, registered with it from the bottom-left so it lands in the empty space. */
.gallery-sidebar::after {
  background: var(--topo-index);
  opacity: calc(var(--topo-art-o) * 5);
  -webkit-mask: url(/img/topo/ridge-tile-index.svg) 0 100% / 640px 640px no-repeat;
  mask: url(/img/topo/ridge-tile-index.svg) 0 100% / 640px 640px no-repeat;
}
.sidebar-block {
  background: var(--bg-glass-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .sidebar-block { background: rgba(26, 26, 26, 0.92); }
.sidebar-block + .sidebar-block { margin-top: 8px; }
.sidebar-heading { margin: 0 0 16px; font-size: 1.05rem; font-weight: 600; color: var(--accent-primary); list-style: none; }
.sidebar-heading::-webkit-details-marker { display: none; }
.sidebar-heading > span { display: none; }
@supports selector(::details-content) {
  @media (min-width: 769px) {
    .sidebar-block > summary { display: none; }
    .sidebar-block::details-content { content-visibility: visible; }
  }
}

.places-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: 8px; font-size: 0.875rem; color: var(--text-primary); }
.places-crumbs > * + *::before { content: "›"; margin-right: 6px; color: var(--text-secondary); }
.places-crumb { padding: 0; border: 0; background: none; font: inherit; color: var(--accent-primary); cursor: pointer; }
.places-crumb:hover { text-decoration: underline; }
.places-crumbs > span { font-weight: 600; }
.places-list { margin: 0; padding: 0; list-style: none; }
.places-list:empty { display: none; }
.places-list li + li { border-top: 1px solid var(--border); }
.places-row { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 0; border: 0; background: none; font: inherit; font-size: 0.875rem; color: var(--text-primary); text-align: left; cursor: pointer; }
.places-row::after { content: "›"; color: var(--text-secondary); }
.places-row:hover { color: var(--accent-primary); }
.places-row:focus-visible { outline: 2px solid var(--color-info); outline-offset: -2px; }
.places-row--rest { font-style: italic; color: var(--text-secondary); }
.places-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.places-row-count { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

/* Phones: the sidebar stacks above the content as a closed disclosure. */
@media (max-width: 768px) {
  .gallery-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .gallery-search-wrap { flex-basis: 100%; }
  .gallery-sidebar { position: static; height: auto; overflow: visible; padding: 0; border: 0; background: none; }
  .gallery-sidebar::before, .gallery-sidebar::after { content: none; }
  /* The disclosure line is the planner's .active-plans-toggle: caret turns when open. */
  .sidebar-heading { display: flex; align-items: center; min-height: 44px; margin: -12px 0; cursor: pointer; }
  .sidebar-heading > span { display: inline; white-space: pre; }
  .sidebar-heading::after { content: "▾"; margin-left: auto; font-size: 0.8em; color: var(--text-secondary); transition: transform 0.2s ease; }
  .sidebar-block[open] > .sidebar-heading { margin-bottom: 4px; }
  .sidebar-block[open] > .sidebar-heading::after { transform: rotate(180deg); }
  .places-row { min-height: 44px; font-size: 14px; }
}


.gallery-filter { margin: 0 0 8px; font-size: 0.875rem; color: var(--text-secondary); }

.gallery-map-empty {
  margin: 48px 0;
  text-align: center;
  color: var(--text-secondary);
}

/* PhotoMap pins — the planner's teardrop pin and group count, camera glyph. */
.photo-pin-wrap { background: none; border: none; }
.photo-pin { width: 30px; animation: photoPinIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
@keyframes photoPinIn { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .photo-pin { animation: none; } }
.photo-pin-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 auto;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  background: var(--accent-fill);
}
.photo-pin-camera { display: block; transform: rotate(45deg); color: rgba(255, 255, 255, 0.95); }
.photo-pin--gps .photo-pin-body { background: var(--bg-card); border-color: var(--accent-fill); }
.photo-pin--gps .photo-pin-camera { color: var(--accent-fill); }
.photo-pin-count {
  position: absolute; left: -10px; top: 50%; transform: translateY(-50%) rotate(45deg);
  min-width: 15px; height: 15px; padding: 0 3px; box-sizing: border-box; border-radius: 8px;
  background: var(--text-primary); color: var(--bg-elevated); border: 1px solid var(--bg-elevated);
  font-size: 9px; font-weight: 700; line-height: 13px; text-align: center;
}

/* Popups stay light in both themes: shared.css re-pins the light tokens on .leaflet-popup. */
.photo-pin-popup .leaflet-popup-content-wrapper { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 10px rgba(40, 32, 18, 0.18); }
.photo-pin-popup .leaflet-popup-tip { background: var(--bg-card); }
.photo-pin-popup .leaflet-popup-content { margin: 8px; }
.photo-pin-card { display: flex; flex-direction: column; gap: 2px; width: 220px; color: var(--text-primary); }
.photo-pin-card-thumb { display: block; width: 100%; height: 140px; margin-bottom: 6px; object-fit: cover; border-radius: 6px; }
.photo-pin-card-title { font-size: 0.85rem; font-weight: 600; overflow-wrap: anywhere; }
.photo-pin-card-meta { font-size: 0.75rem; color: var(--text-secondary); }
.photo-pin-card-meta:empty { display: none; }
.photo-pin-card-open { margin-top: 8px; min-height: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elevated); color: var(--accent-on-tint); font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.photo-pin-list { display: flex; flex-direction: column; gap: 2px; width: 240px; max-height: 280px; overflow-y: auto; }
.photo-pin-list-row { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 6px; border: 0; border-radius: 8px; background: none; font: inherit; color: var(--text-primary); text-align: left; cursor: pointer; }
.photo-pin-card-open:hover, .photo-pin-list-row:hover { background: var(--bg-subtle); }
.photo-pin-card-open:focus-visible, .photo-pin-list-row:focus-visible { outline: 2px solid var(--color-info); outline-offset: -2px; }
.photo-pin-list-thumb { flex: none; width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }
.photo-pin-list-text { display: flex; flex-direction: column; min-width: 0; }
.photo-pin-list-title { font-size: 0.82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-pin-list-date { font-size: 0.72rem; color: var(--text-secondary); }
