:root {
  --paper: #f2ecd8;
  --paper-card: #f6f1e0;
  --ink: #2c6266;
  --ink-soft: #6c8f8f;
  --rule: rgba(44, 98, 102, 0.35);
  --serif: "IM Fell English", "EB Garamond", Georgia, serif;
  --text: "EB Garamond", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
}

#map { position: absolute; inset: 0; }

/* ---------- Paper: fine grain + mottled watercolour wash + aged edges ---------- */
.paper-wash,
.paper-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.paper-wash {
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(120, 100, 60, 0.18) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1200' height='1200'><filter id='w'><feTurbulence type='fractalNoise' baseFrequency='0.004' numOctaves='4' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.55  0 0 0 0 0.7  0 0 0 0 0.66  1.4 0 0 0 -0.62'/></filter><rect width='100%25' height='100%25' filter='url(%23w)'/></svg>");
  background-size: 100% 100%, cover;
  background-repeat: no-repeat;
  opacity: 0.55;
}
.paper-grain {
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.36  0 0 0 0 0.24  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  opacity: 0.45;
}

/* ---------- Panel: a field-journal label ---------- */
.panel {
  position: absolute;
  top: 22px;
  left: 22px;
  width: 310px;
  max-height: calc(100% - 44px);
  display: flex;
  flex-direction: column;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  outline: 1px solid var(--rule);
  outline-offset: -6px;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 10px 30px rgba(60, 50, 20, .12);
}

/* The title doubles as the collapse toggle */
.panel-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 20px 20px 14px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.panel-toggle:focus-visible { outline: 1px dashed var(--ink-soft); outline-offset: -10px; }
.titles { flex: 1; min-width: 0; }
.chevron {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--ink-soft);
  transition: transform .25s;
}
.panel.collapsed .chevron { transform: rotate(-90deg); }

.panel-body {
  overflow: auto;
  padding: 0 20px 14px;
  overscroll-behavior: contain;
}
.panel.collapsed .panel-body { display: none; }
.panel.collapsed .panel-toggle { padding-bottom: 18px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 30px;
  line-height: 1;
  white-space: nowrap;
}
h1 em { color: var(--ink-soft); }

.sub {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
}

.legend {
  list-style: none;
  margin: 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--rule);
}
.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 4px;
  margin: 0 -4px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  transition: opacity .2s;
}
@media (hover: hover) {
  .legend li:hover .name { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
}
.legend li.off { opacity: .3; }
.legend .name { flex: 1; font-family: var(--serif); font-style: italic; }
.legend .count { font-size: 14px; color: var(--ink-soft); font-variant-numeric: oldstyle-nums tabular-nums; }
/* Fixed icon column: silhouette stamps at 40px, engraving cut-outs larger */
.legend .stamp { width: 58px; height: 40px; }
.legend .cutout { height: 64px; margin: -8px 0; }

.credits {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.credits a { color: inherit; }
.credits:empty { display: none; }

/* ---------- Stamps ---------- */
.stamp {
  display: block;
  flex: none;
  overflow: visible;
  transform: rotate(var(--r, 0deg));
}
.stamp-paper { fill: var(--paper); fill-opacity: 0.85; }

.marker { cursor: pointer; mix-blend-mode: multiply; }
.marker .pin { position: relative; }
.marker .stamp {
  width: var(--s, 30px);
  height: var(--s, 30px);
  transition: transform .2s;
}
.marker:hover .stamp { transform: rotate(var(--r, 0deg)) scale(1.15); }

/* Engraving cut-outs: paper pieces laid on the map */
.marker:has(.cutout) { mix-blend-mode: normal; }
.marker .cutout { width: calc(var(--s, 30px) * 1.7); height: calc(var(--s, 30px) * 1.7); }
.marker .n { color: var(--ink); }
.marker .n {
  position: absolute;
  bottom: -6px;
  right: -14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1;
  text-shadow: 0 0 2px var(--paper), 0 0 2px var(--paper);
}
.marker.hidden { display: none; }

/* ---------- Popup ---------- */
.maplibregl-popup-content {
  padding: 12px 16px;
  border-radius: 0;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  font-family: var(--text);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(60, 50, 20, .15);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--paper-card); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--paper-card); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--paper-card); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--paper-card); }
.pop-title { font-family: var(--serif); font-style: italic; font-size: 18px; }
.pop-meta { margin-top: 2px; font-size: 14px; color: var(--ink-soft); }
.pop-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  color: #6e1f3a;
  font-size: 11px;
  letter-spacing: .12em;
  transform: rotate(-2deg);
}
.pop-link { display: inline-block; margin-top: 8px; font-size: 14px; color: var(--ink); }

.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(246, 241, 224, .7) !important; }
.maplibregl-ctrl-group { background: var(--paper-card); border-radius: 0; box-shadow: 0 0 0 1px var(--rule); }

@media (max-width: 900px) {
  .panel { width: 290px; }
  h1 { font-size: 27px; }
}

/* Phones: the panel becomes a bottom sheet, collapsed by default */
@media (max-width: 600px) {
  .panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 60%;
  }
  .panel-toggle { padding: 14px 16px 10px; }
  .panel.collapsed .panel-toggle { padding-bottom: 14px; }
  .panel-body { padding: 0 16px 10px; }
  h1 { font-size: 24px; }
  .sub { margin-top: 4px; }
  .legend li { font-size: 15px; }
  .legend .stamp { width: 48px; height: 34px; }
  .legend .cutout { height: 52px; margin: -6px 0; }
  .panel.collapsed .chevron { transform: rotate(180deg); }
}
