* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", sans-serif;
  color: #1f2937;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  /* Match OSM's ocean tile color so the Mercator polar void above/below the
     tiles blends in as "more ocean" instead of an awkward gray band. Visible
     mainly on tall/narrow viewports (mobile portrait) when fitBounds zooms out
     to fit east-west-spread pins. */
  background: #aad3df;
}

/* Floating top-left group of controls over the full-screen map.
   Loosely connected (not one card): a brand chip above a lighter search field. */
#top-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 1000;
  width: 300px;
  max-width: calc(100vw - 28px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-header {
  background: rgba(255, 255, 255, 0.85);
  padding: 7px 13px;
  border-radius: 11px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.10);
  backdrop-filter: blur(8px);
}
.app-header h1 { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
.tagline { margin: 1px 0 0; font-size: 0.7rem; color: #9ca3af; }

/* Secondary actions row: visit-log toggle + logout, sharing one styled look. */
.control-row {
  display: flex;
  gap: 8px;
}
#list-toggle,
#logout-btn {
  white-space: nowrap;
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  color: #4b5563;
  padding: 6px 11px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
#list-toggle:hover,
#logout-btn:hover { background: rgba(255, 255, 255, 0.9); }
#logout-btn { color: #9ca3af; }

/* Drawer opens just below the controls row when toggled. */
#pin-drawer {
  width: 100%;
  max-height: 50vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
  padding: 10px;
}
#pin-drawer.hidden { display: none; }
#search-form {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(8px);
  overflow: hidden;
}
#search-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  font: inherit;
  font-size: 0.83rem;
  padding: 6px 11px;
  background: transparent;
}
#search-input::placeholder { color: #9ca3af; }
#search-form button {
  border: none;
  background: transparent;
  font-size: 0.85rem;
  opacity: 0.6;
  padding: 0 9px;
  cursor: pointer;
}
#search-form button:hover { opacity: 1; }
.search-results {
  list-style: none;
  margin: 8px 0 0;
  padding: 6px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  max-height: 320px;
  overflow-y: auto;
}
.search-results.hidden { display: none; }
.search-results li {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1.35;
}
.search-results li:hover { background: #f3f4f6; }
.search-results li.searching {
  color: #6b7280;
  cursor: default;
}
.search-results li.searching:hover { background: none; }

/* Pin list (grouped by visited date) */
.date-group { margin-bottom: 14px; }
.date-group-header {
  font-size: 0.78rem;
  font-weight: 700;
  color: #2563eb;
  padding: 4px 0;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 6px;
}
.pin-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.pin-item:hover { background: #f3f4f6; }
.pin-item .pin-title { font-size: 0.88rem; font-weight: 600; }
.pin-item .pin-loc { font-size: 0.76rem; color: #6b7280; margin-top: 2px; }
.pin-empty {
  font-size: 0.82rem;
  color: #9ca3af;
  padding: 8px 2px;
}

.hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(17, 24, 39, 0.78);
  color: #fff;
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 0.82rem;
  pointer-events: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: opacity 0.6s ease;
}
.hint.hint--hidden { opacity: 0; }

.panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1001;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}
.panel-header h2 { margin: 0; font-size: 1.05rem; }

.close-btn {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #9ca3af;
}
.close-btn:hover { color: #374151; }

#pin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 16px;
}
#pin-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
}
.req { color: #ef4444; }
#pin-form input,
#pin-form textarea {
  font: inherit;
  font-weight: 400;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}
#pin-form input:focus,
#pin-form textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
#pin-form textarea { resize: vertical; }

.coords {
  font-size: 0.75rem;
  color: #6b7280;
}

/* Offered after picking a photo whose GPS differs from the pin's spot. */
.location-suggest {
  font: inherit;
  font-size: 0.8rem;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}
.location-suggest:hover { background: #f3f4f6; }
.location-suggest.hidden { display: none; }

#pin-form input[type="file"] {
  font-size: 0.78rem;
  border: none;
  padding: 0;
}
/* The native "파일 선택" button needs its own styling to match the rounded fields. */
#pin-form input[type="file"]::file-selector-button,
#pin-form input[type="file"]::-webkit-file-upload-button {
  font: inherit;
  font-size: 0.8rem;
  padding: 7px 12px;
  margin-right: 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}
#pin-form input[type="file"]::file-selector-button:hover {
  background: #f3f4f6;
}
.photo-preview {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 8px;
}
.photo-preview.hidden { display: none; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.actions button {
  flex: 1;
  font: inherit;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  cursor: pointer;
}
.actions button:hover { background: #f3f4f6; }
.actions .primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: 600;
}
.actions .primary:hover { background: #1d4ed8; }

/* Login gate overlay */
#auth-screen {
  position: absolute;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #1e3a5f 0%, #2563eb 100%);
}
#auth-screen.hidden { display: none; }

.auth-card {
  width: 340px;
  max-width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  padding: 28px 24px;
  text-align: center;
}
/* The pin emoji sits left of the wordmark; centering the whole "📍 Mapinn"
   string pushes "Mapinn" right of center, so shift the group left to balance it. */
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; transform: translateX(-0.7em); }
.auth-sub { margin: 0 0 18px; font-size: 0.88rem; color: #6b7280; }
#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-email,
#auth-password {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}
#auth-email:focus,
#auth-password:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
#auth-form .primary {
  font: inherit;
  font-weight: 600;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
#auth-form .primary:hover { background: #1d4ed8; }

/* In-app toast (replaces native alert): a dark pill that fades in/out at the
   bottom-center, red for errors. */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 12px);
  z-index: 3000;
  max-width: calc(100vw - 32px);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: rgba(185, 28, 28, 0.95); }

/* Confirm dialog (replaces native confirm): centered card over a dim overlay. */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.45);
}
.modal-card {
  width: 320px;
  max-width: 100%;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  padding: 22px 20px 16px;
}
.modal-message {
  margin: 0 0 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #1f2937;
  text-align: center;
}
.modal-actions { display: flex; gap: 8px; }
.modal-actions button {
  flex: 1;
  font: inherit;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  cursor: pointer;
}
.modal-actions button:hover { background: #f3f4f6; }
.modal-confirm {
  font-weight: 600;
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.modal-confirm:hover { background: #1d4ed8; }
.modal-confirm.danger { background: #dc2626; border-color: #dc2626; }
.modal-confirm.danger:hover { background: #b91c1c; }

/* Full-screen photo viewer (lightbox). object-fit: contain keeps the whole
   photo visible in any orientation; safe-area padding clears notches on phones. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}
.auth-message {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: #1f2937;
  line-height: 1.45;
}
.auth-message.hidden { display: none; }
.auth-hint {
  margin: 14px 0 0;
  font-size: 0.72rem;
  color: #9ca3af;
  line-height: 1.45;
}

/* Popup contents */
.pin-popup .pin-photo {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 6px;
  display: block;
  cursor: zoom-in;
}
.pin-popup h3 { margin: 0 0 4px; font-size: 1rem; }
.pin-popup .meta { font-size: 0.8rem; color: #6b7280; margin: 2px 0; }
.pin-popup .memo { font-size: 0.85rem; margin: 8px 0 0; white-space: pre-wrap; }
.pin-popup .pin-actions {
  display: flex;
  gap: 14px;
  margin-top: 10px;
}
.pin-popup .edit-link,
.pin-popup .delete-link {
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
}
.pin-popup .edit-link { color: #2563eb; }
.pin-popup .delete-link { color: #ef4444; }

/* Cluster click → list of the pins held at that spot. */
.cluster-list h3 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: #6b7280;
  font-weight: 600;
}
.cluster-list {
  max-height: 220px;
  overflow-y: auto;
}
.cluster-pin-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: none;
  border-radius: 6px;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.cluster-pin-item:hover { background: #f3f4f6; }
.cluster-pin-item .cpi-title { font-size: 0.88rem; color: #111827; }
.cluster-pin-item .cpi-date { font-size: 0.75rem; color: #6b7280; white-space: nowrap; }

/* Recolor cluster bubbles to a single blue, deepening with count — replaces the
   plugin's green/yellow/red tiers (which read like an air-quality map). Loaded
   after MarkerCluster.Default.css, so these win. */
.marker-cluster-small  { background-color: rgba(147, 197, 253, 0.5); } /* blue-300 halo */
.marker-cluster-small div  { background-color: rgba(59, 130, 246, 0.9); } /* blue-500 */
.marker-cluster-medium { background-color: rgba(96, 165, 250, 0.5); } /* blue-400 halo */
.marker-cluster-medium div { background-color: rgba(37, 99, 235, 0.9); } /* blue-600 */
.marker-cluster-large  { background-color: rgba(59, 130, 246, 0.5); } /* blue-500 halo */
.marker-cluster-large div  { background-color: rgba(29, 78, 216, 0.92); } /* blue-700 */
.marker-cluster span { color: #fff; font-weight: 600; }

/* ── Mobile portrait (≤480px, e.g. iPhone 15 Pro at 393px) ──────────────────
   The desktop layout above is unchanged. On a narrow screen the top-left
   controls and the top-right add-pin form would overlap, so the controls span
   the top full-width and the add-pin form becomes a bottom sheet. */
@media (max-width: 480px) {
  /* Controls span the top instead of a fixed 300px column. */
  #top-panel {
    top: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }

  /* Add-pin form slides up from the bottom, full width. */
  #form-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* 16px stops iOS Safari from auto-zooming the page when an input is focused. */
  #search-input,
  #pin-form input,
  #pin-form textarea {
    font-size: 16px;
  }

  /* Keep the hint above the home indicator / browser chrome. */
  .hint { bottom: calc(24px + env(safe-area-inset-bottom)); }
}
