:root {
  --accent: #d94f2b;
  --accent-dark: #b93c1c;
  --ink: #1c2024;
  --map-bg: #c1e5fb;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  background: var(--map-bg);
  /* Ocean blue, with a white strip at the bottom for Antarctica. */
  background: linear-gradient(
    to bottom,
    var(--map-bg) calc(100% - max(10px, env(safe-area-inset-bottom))),
    #fff calc(100% - max(10px, env(safe-area-inset-bottom)))
  );
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body.viewer-open {
  overflow: hidden;
}

/* ----------------------------------------------------------------- map --- */

#map {
  position: fixed;
  inset: 0;
  background: var(--map-bg);
}

.leaflet-container {
  font-family: var(--font);
}

/* Keep Leaflet's controls clear of the device safe areas. The map itself
   stays full-bleed and must not take safe-area padding. */
.leaflet-top {
  top: env(safe-area-inset-top);
}

.leaflet-bottom {
  bottom: env(safe-area-inset-bottom);
}

.leaflet-left {
  left: env(safe-area-inset-left);
}

.leaflet-right {
  right: env(safe-area-inset-right);
}

/* Zoom buttons are for mouse and keyboard; touch uses pinch and
   double-tap-drag instead. */
body.touch .leaflet-control-zoom {
  display: none;
}

/* Match Leaflet's own selector so this overrides its default white box. The
   attribution only ever sits over the map / page background, so it needs no
   backing of its own. */
.leaflet-container .leaflet-control-attribution {
  font-size: 10px;
  background: transparent;
}

/* Thumbnail markers ------------------------------------------------------ */

.photo-thumb {
  background: none;
  border: none;
}

.photo-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 2px solid #fff;
  border-radius: 8px;
  background: #dfe3e7;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  transition: transform 140ms ease;
}

.photo-thumb:hover img {
  transform: scale(1.08);
}

.photo-thumb:focus-visible {
  outline: none;
}

.photo-thumb:focus-visible img {
  transform: scale(1.08);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95), 0 0 0 4px rgba(0, 0, 0, 0.5);
}

/* Clusters: a fanned stack of thumbnails with a count --------------------- */

.cluster-stack {
  background: none;
  border: none;
}

/* A focused stack drops the UA outline; the hover-like lift is its only cue. */
.cluster-stack:focus-visible {
  outline: none;
}

.cluster-stack:focus-visible .stack img {
  scale: 1.08;
}

.stack {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.stack img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  object-fit: cover;
  border: 2px solid #fff;
  border-radius: 8px;
  background: #dfe3e7;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: scale 140ms ease;
}

.stack-2 img:nth-child(1) {
  z-index: 1;
  transform: translate(-5px, 4px) rotate(-5deg);
  filter: brightness(0.94);
}

.stack-2 img:nth-child(2) {
  z-index: 2;
  transform: translate(5px, -3px) rotate(4deg);
}

.stack-3 img:nth-child(1) {
  z-index: 1;
  transform: translate(-7px, 4px) rotate(-6deg);
  filter: brightness(0.9);
}

.stack-3 img:nth-child(2) {
  z-index: 2;
  transform: translate(7px, 4px) rotate(6deg);
  filter: brightness(0.95);
}

.stack-3 img:nth-child(3) {
  z-index: 3;
}

/* Grow every card in the stack, like a single thumbnail. The `scale`
   property composes with each card's own translate/rotate fan transform. */
.stack:hover img {
  scale: 1.08;
}

/* Markercluster animates joins/splits over 0.3s, which visibly lags our
   continuous smooth zoom: every reposition during a zoom gets transitioned,
   so markers float behind the map. Speed that up so a level change is a quick
   pop instead. The spider legs follow the same timing. */
.leaflet-cluster-anim .leaflet-marker-icon,
.leaflet-cluster-anim .leaflet-marker-shadow {
  transition: transform 40ms ease-out, opacity 40ms ease-in;
}

.leaflet-cluster-spider-leg {
  transition: stroke-dashoffset 40ms ease-out, stroke-opacity 40ms ease-in;
}

/* -------------------------------------------------------------- viewer --- */

/* A white stage, the photo, and a close button. Nothing else.
   The photo keeps a 10% gutter on every side; the count sits at the page's
   top edge, the date at the bottom, and the desktop arrows live in the side
   gutters, rather than pushing the photo. */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  animation: viewer-in 140ms ease-out;
}

.viewer[hidden] {
  display: none;
}

/* The dialog container is the initial focus target, so it must never show a
   ring. Rings belong on the controls, reached deliberately with Tab. */
.viewer:focus,
.viewer:focus-visible {
  outline: none;
}

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

.viewer-body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
}

.viewer-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-frame img {
  display: block;
  width: auto;
  height: auto;
  /* 10% margins on all sides. The photo is centred on its own, so top and
     bottom margins match. */
  max-width: 80vw;
  max-height: 80vh;
  /* The photo itself is always fully opaque; the stage behind it is solid white. */
  opacity: 0;
  transition: opacity 160ms ease;
}

/* Count and date are out-of-flow overlays pinned to the page's top and bottom
   edges, so they never shift the photo off centre. */
.viewer-count,
.viewer-date {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(28, 32, 36, 0.62);
  font-size: 14px;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}

.viewer-count {
  top: max(12px, env(safe-area-inset-top));
  color: rgba(28, 32, 36, 0.55);
  font-variant-numeric: tabular-nums;
}

.viewer-date {
  bottom: max(12px, env(safe-area-inset-bottom));
}

.viewer-count[hidden] {
  display: none;
}

.viewer-frame img.is-loaded {
  opacity: 1;
}

.viewer-spinner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid rgba(28, 32, 36, 0.22);
  border-top-color: rgba(28, 32, 36, 0.9);
  animation: spin 700ms linear infinite;
}

.viewer-spinner[hidden] {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.viewer-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(28, 32, 36, 0.1);
  color: rgba(28, 32, 36, 0.9);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

/* Icons are SVG, not glyphs: the viewBox is symmetric so flex centring puts
   them dead-centre, with no dependence on font metrics. */
.viewer-close svg,
.viewer-nav svg {
  display: block;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viewer-close:hover {
  background: rgba(28, 32, 36, 0.18);
  color: var(--ink);
}

.viewer-close:focus-visible {
  outline: 2px solid rgba(28, 32, 36, 0.6);
  outline-offset: 2px;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(28, 32, 36, 0.1);
  color: rgba(28, 32, 36, 0.9);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.viewer-nav[hidden] {
  display: none;
}

.viewer-nav:hover {
  background: rgba(28, 32, 36, 0.18);
  color: var(--ink);
}

.viewer-nav:focus-visible {
  outline: 2px solid rgba(28, 32, 36, 0.6);
  outline-offset: 2px;
}

.viewer-prev {
  left: max(12px, env(safe-area-inset-left));
}

.viewer-next {
  right: max(12px, env(safe-area-inset-right));
}

/* One-off mobile hint: the arrows are hidden on touch, so explain the
   gestures instead. Fades in on the first multi-photo album of the session
   and is dismissed by the first interaction (app.js). */
.viewer-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(28, 32, 36, 0.55);
  color: #fff;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-50% + 8px));
  transition: opacity 220ms ease, transform 220ms ease;
}

.viewer-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.viewer-hint-arrow {
  font-size: 16px;
  opacity: 0.8;
}

/* On touch devices the album arrows stay in the DOM for assistive tech but
   are visually hidden; swipe replaces them. touch-action: none lets the
   viewer claim horizontal/vertical drags instead of the browser. */
body.touch .viewer {
  touch-action: none;
}

body.touch .viewer-nav {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* -------------------------------------------------------------- status --- */

.status {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  margin: 0;
  padding: 10px 16px;
  max-width: min(90vw, 460px);
  border-radius: 999px;
  background: rgba(28, 32, 36, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.status[hidden] {
  display: none;
}

/* ------------------------------------------------------------- mobile --- */

@media (max-width: 560px) {
  .viewer-close {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .viewer-nav {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .viewer-prev {
    left: max(8px, env(safe-area-inset-left));
  }

  .viewer-next {
    right: max(8px, env(safe-area-inset-right));
  }
}

@media (prefers-reduced-motion: reduce) {
  .viewer,
  .viewer-frame img,
  .viewer-nav,
  .viewer-hint,
  .photo-thumb img,
  .stack img,
  .leaflet-cluster-anim .leaflet-marker-icon,
  .leaflet-cluster-spider-leg {
    animation: none;
    transition: none;
  }
}
