:root {
  --paper: #f1ede6;
  --paper-2: #e7dfd2;
  --ink: #4b2b1a;
  --ink-soft: #7a604c;
  --rule: #cbbba5;
  --accent: #8c4a2f;
  --font: "EB Garamond", Garamond, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font: 17px/1.35 var(--font); }
#map { position: absolute; inset: 0; background: var(--paper); }
button, input { font: inherit; color: inherit; }
small { color: var(--ink-soft); font-size: 0.85em; }

/* Panel */
#panel {
  position: absolute; z-index: 1000; top: 12px; left: 12px;
  width: 300px; max-height: calc(100% - 24px); overflow-y: auto;
  background: var(--paper); border: 1px solid var(--rule);
  box-shadow: 0 2px 10px rgba(60, 35, 20, 0.25); padding: 14px 16px 10px;
}
#panel header { border-bottom: 2px solid var(--ink); padding-bottom: 8px; margin-bottom: 4px; }
#panel h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 0.02em; line-height: 1.05; }
#panel h1 span { font-style: italic; font-weight: 400; }
#panel header p { margin: 4px 0 0; font-size: 15px; color: var(--ink-soft); font-style: italic; }
#panel section { padding: 8px 0 6px; border-bottom: 1px solid var(--rule); }
#panel section:last-child { border-bottom: 0; }
#panel h2 {
  margin: 0 0 4px; font-size: 13px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-soft);
}
#panel label { display: flex; gap: 7px; align-items: baseline; padding: 2px 0; cursor: pointer; }
#panel input[type=checkbox], #panel input[type=radio] { accent-color: var(--ink); margin: 0; transform: translateY(1px); }
#panel label.slider { align-items: center; padding-top: 6px; }
#panel label.slider input { flex: 1; accent-color: var(--ink); }

#themes { margin: 2px 0 6px 20px; }
#themes label { font-size: 15px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--paper); box-shadow: 0 0 0 1px var(--ink); flex: none; transform: translateY(-1px); }

#panel button#browse, .overlay button, .overlay a.source {
  background: var(--paper-2); border: 1px solid var(--rule); padding: 3px 10px;
  cursor: pointer; text-decoration: none; color: var(--ink); font-size: 15px;
}
#panel button#browse { margin: 0 0 6px 20px; }
#panel button#browse:hover, .overlay button:hover, .overlay a.source:hover { background: var(--rule); }

#panel-toggle { display: none; }

/* Leaflet look */
.leaflet-container { font-family: var(--font); background: var(--paper); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--paper); color: var(--ink); border-color: var(--rule); }
.leaflet-control-attribution { background: rgba(241, 237, 230, 0.85) !important; font-size: 12px; color: var(--ink-soft); }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-control-scale-line { background: rgba(241, 237, 230, 0.8); border-color: var(--ink); color: var(--ink); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--paper); color: var(--ink); border-radius: 2px; box-shadow: 0 2px 10px rgba(60, 35, 20, 0.35); }
.leaflet-popup-content { margin: 10px 12px; font-size: 15px; line-height: 1.3; }
.leaflet-popup-content h3 { margin: 0 0 2px; font-size: 17px; font-weight: 600; }
.leaflet-popup-content p { margin: 2px 0; }
.leaflet-tooltip { background: var(--paper); color: var(--ink); border-color: var(--rule); font-family: var(--font); font-size: 14px; }

.photo-pop img { display: block; width: 260px; max-width: 100%; height: auto; margin-bottom: 6px; cursor: zoom-in; border: 1px solid var(--rule); }
.photo-pop .where { color: var(--ink-soft); font-style: italic; }

.photo-marker span {
  display: block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--paper); box-shadow: 0 0 0 1px var(--ink), 0 1px 3px rgba(0, 0, 0, 0.4);
}
.photo-cluster div {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  border-radius: 50%; background: var(--ink); color: var(--paper); font-weight: 600; font-size: 14px;
  border: 2px solid var(--paper); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

/* Overlays */
.overlay[hidden] { display: none; }
.overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(40, 25, 15, 0.82); }
.overlay .close {
  position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; padding: 0;
  font-size: 28px; line-height: 1; z-index: 2;
}

#gallery .sheet {
  position: absolute; inset: 24px; max-width: 1100px; margin: 0 auto;
  background: var(--paper); display: flex; flex-direction: column;
}
#gallery header { padding: 12px 64px 8px 18px; border-bottom: 1px solid var(--rule); }
#gallery header h2 { margin: 0; font-size: 22px; font-weight: 600; }
#gallery .grid {
  overflow-y: auto; padding: 14px 18px; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
#gallery .grid button {
  display: flex; flex-direction: column; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; font-size: 14px; line-height: 1.2;
}
#gallery .grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid var(--rule); margin-bottom: 4px; background: var(--paper-2); }
#gallery .grid button:hover img { outline: 2px solid var(--ink); }
#gallery .grid small { display: block; }

#viewer { background: rgba(30, 18, 10, 0.96); }
#viewer figure {
  position: absolute; inset: 16px 64px; margin: 0; display: flex; gap: 20px; align-items: center; justify-content: center;
}
#viewer img { max-width: calc(100% - 340px); max-height: 100%; object-fit: contain; background: var(--paper-2); box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5); }
#viewer figcaption {
  width: 320px; flex: none; max-height: 100%; overflow-y: auto;
  background: var(--paper); padding: 14px 16px; font-size: 16px;
}
#viewer figcaption h2 { margin: 0 0 6px; font-size: 21px; font-weight: 600; line-height: 1.15; }
#viewer figcaption p { margin: 0 0 8px; }
#viewer .meta { font-style: italic; color: var(--ink-soft); }
#viewer .credit { font-size: 14px; color: var(--ink-soft); }
#viewer .actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#viewer .counter { color: var(--ink-soft); font-size: 14px; margin-left: auto; }
#viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; padding: 0;
  font-size: 40px; line-height: 1; background: rgba(241, 237, 230, 0.9);
}
#viewer .prev { left: 10px; }
#viewer .next { right: 10px; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  #panel-toggle {
    display: block; position: absolute; z-index: 1001; top: 10px; right: 10px;
    background: var(--paper); border: 1px solid var(--rule); padding: 6px 12px; box-shadow: 0 2px 6px rgba(60, 35, 20, 0.3);
  }
  #panel { left: 10px; right: 10px; top: 52px; width: auto; max-height: calc(100% - 64px); display: none; }
  #panel.open { display: block; }
  .leaflet-top.leaflet-right { top: 46px; }
  .leaflet-control-attribution { font-size: 11px; }
  #gallery .sheet { inset: 8px; }
  #gallery .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); padding: 10px; }
  #viewer figure { inset: 56px 8px 8px; flex-direction: column; gap: 8px; }
  #viewer img { max-width: 100%; max-height: 55%; }
  #viewer figcaption { width: 100%; flex: 1; }
  #viewer .nav { top: 28px; width: 40px; height: 40px; font-size: 30px; transform: none; }
  #viewer .prev { left: 8px; }
  #viewer .next { left: 54px; right: auto; }
}
