* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background: #F4EFE5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Toolbar ── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  z-index: 100;
  flex-shrink: 0;
}
#toolbar h1 { font-size: 14px; font-weight: 600; color: #e0e0e0; margin-right: 4px; }
.sep { width: 1px; height: 22px; background: #0f3460; }
.tool-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 6px;
  border: 1px solid #0f3460; background: #1a1a2e;
  color: #b0b8c8; font-size: 12px; cursor: pointer;
  transition: all 0.15s; user-select: none; white-space: nowrap;
}
.tool-btn:hover { background: #0f3460; color: #e0e0e0; }
.tool-btn.active { background: #0f3460; color: #4fc3f7; border-color: #4fc3f7; }
.tool-btn.danger:hover { background: #3d1515; color: #ef9a9a; border-color: #ef9a9a; }
#marker-count { font-size: 11px; color: #546e7a; }
#hint { margin-left: auto; font-size: 11px; color: #37474f; }

/* ── Viewport ── */
#viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  touch-action: none;
}
#viewport.panning { cursor: grabbing; }
#viewport.pin-mode { cursor: crosshair; }

#map-container {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
  transform: translateZ(0);
}
#base-map { display: block; user-select: none; pointer-events: none; }

.map-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.map-layer.hidden { display: none; }

#markers-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* ── Hamburger button ── */
#menu-btn {
  position: absolute;
  top: 12px; left: 12px;
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  z-index: 110;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
  padding: 0;
  transition: background 0.15s;
}
#menu-btn:hover { background: rgba(255,255,255,0.35); }
#menu-btn span {
  display: block;
  width: 18px; height: 2px;
  background: rgba(0,0,0,0.6);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
#menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#menu-btn.open span:nth-child(2) { opacity: 0; }
#menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Layers panel (floating glass) ── */
#layers-panel {
  position: absolute;
  left: 12px;
  top: 62px;
  width: 220px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  z-index: 100;
  overflow: hidden;
  padding: 12px 0 8px;
  transform-origin: top left;
  transition: opacity 0.2s, transform 0.2s;
}
#layers-panel.hidden {
  opacity: 0;
  transform: scale(0.95) translateY(-6px);
  pointer-events: none;
}

@media (max-width: 600px) {
  #layers-panel {
    left: 8px; right: 8px; top: 62px;
    width: auto;
  }
  .layer-row { padding: 10px 16px; }
  .layer-name { font-size: 15px; }
  .layer-toggle { width: 48px; height: 28px; border-radius: 14px; }
  .layer-toggle::after { width: 22px; height: 22px; }
  .layer-row.on .layer-toggle::after { transform: translateX(20px); }
}

/* ── Zoom presets ── */
#zoom-presets {
  display: flex;
  gap: 4px;
  padding: 0 12px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  margin-bottom: 6px;
}
.zoom-preset {
  flex: 1;
  padding: 5px 0;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.35);
  color: rgba(0,0,0,0.55);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.zoom-preset:hover { background: rgba(255,255,255,0.55); color: rgba(0,0,0,0.75); }
.zoom-preset.active { background: #fff; color: #1a1a2e; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.15); }

/* ── Layer rows ── */
#layers-list { padding: 0; }

.layer-section-header {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(0,0,0,0.45);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.layer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
}
.layer-row:hover { background: rgba(255,255,255,0.15); }

.layer-name {
  font-size: 13px;
  color: rgba(0,0,0,0.75);
  font-weight: 400;
}

/* iOS-style toggle */
.layer-toggle {
  width: 42px;
  height: 26px;
  border-radius: 13px;
  background: rgba(120,120,128,0.25);
  position: relative;
  flex-shrink: 0;
  transition: background 0.25s;
}
.layer-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.layer-row.on .layer-toggle { background: #34c759; }
.layer-row.on .layer-toggle::after { transform: translateX(16px); }

/* ── Zoom +/- buttons (bottom right) ── */
#zoom-controls {
  position: absolute;
  bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 50;
}
.zoom-btn {
  width: 34px; height: 34px; border-radius: 7px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.zoom-btn:hover { background: rgba(255,255,255,0.35); }

/* ── Legend pins overlay ── */
#legend-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 60;
}
.legend-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: all;
  cursor: pointer;
}
.legend-pin-circle {
  width: 28px; height: 28px;
  border-radius: 40px;
  border: 2px solid rgba(97, 0, 178, 0.60);
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 14px 0 rgba(0, 0, 0, 0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #6100b2;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
  transition: transform 0.15s;
}
.legend-pin:hover .legend-pin-circle {
  transform: scale(1.15);
}

/* ── Cluster pin ── */
.legend-cluster-circle {
  background: #6100b2;
  color: #fff;
  border-color: rgba(255,255,255,0.9);
  font-size: 13px;
  width: 32px;
  height: 32px;
}

/* ── Legend popup ── */
#legend-popup {
  display: none;
  position: absolute;
  z-index: 200;
  max-width: 280px;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(255,255,255,0.8);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  pointer-events: none;
}
#legend-popup-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #7c5cbf;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #7c5cbf;
  margin-bottom: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
}
#legend-popup-text {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(0,0,0,0.8);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
}

/* ── Markers ── */
.marker { position: absolute; transform: translate(-50%,-100%); cursor: pointer; z-index: 10; }
.marker-pin {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: #ef5350; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.1s, background 0.1s;
}
.marker:hover .marker-pin { background: #ff1744; transform: rotate(-45deg) scale(1.15); }
.marker-label {
  position: absolute; left: 50%; bottom: 30px;
  transform: translateX(-50%);
  background: rgba(22,33,62,0.92); color: #e0e0e0;
  font-size: 11px; padding: 3px 7px; border-radius: 4px;
  white-space: nowrap; pointer-events: none;
  border: 1px solid #0f3460; opacity: 0; transition: opacity 0.15s;
}
.marker:hover .marker-label { opacity: 1; }

/* ── Dialog ── */
#dialog-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 999; }
#label-dialog {
  display: none; position: fixed; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  background: #16213e; border: 1px solid #0f3460;
  border-radius: 10px; padding: 20px; z-index: 1000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6); min-width: 260px;
}
#label-dialog h3 { color: #e0e0e0; font-size: 14px; margin-bottom: 12px; }
#label-input {
  width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid #0f3460; background: #1a1a2e;
  color: #e0e0e0; font-size: 13px; outline: none;
}
#label-input:focus { border-color: #4fc3f7; }
.dialog-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.dialog-actions button { padding: 6px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid #0f3460; }
#dialog-confirm { background: #4fc3f7; color: #0d1117; border-color: #4fc3f7; font-weight: 600; }
#dialog-cancel { background: #1a1a2e; color: #b0b8c8; }
