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

:root {
  --bg-dark: #0a0a0f;
  --bg-card: #15151f;
  --accent-red: #e63946;
  --accent-gold: #f4a261;
  --accent-teal: #2a9d8f;
  --text-primary: #fefefe;
  --text-muted: #8b8b9e;
  --header-height: 90px;
}

@media (max-width: 600px) {
  :root {
    --header-height: 75px;
  }
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Nunito", sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Grain overlay */
.grain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.025;
  z-index: 1000;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%' height='100%' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* Background */
body::before {
  content: "";
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 20% 20%, rgba(230, 57, 70, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(42, 157, 143, 0.05) 0%, transparent 50%);
  z-index: -1;
}

header {
  height: var(--header-height);
  min-height: var(--header-height);
  text-align: center;
  padding: 0.6rem 1rem;
  z-index: 500;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
}

/* Subtle gradient under header */
header::after {
  content: "";
  position: absolute;
  bottom: -30px;
  left: 0;
  right: 0;
  height: 30px;
  background: linear-gradient(to bottom, rgba(10, 10, 15, 0.4) 0%, transparent 100%);
  pointer-events: none;
  z-index: 400;
}

h1 {
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--accent-red) 0%, var(--accent-gold) 50%, var(--accent-teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  opacity: 0.9;
}

.question {
  font-size: clamp(0.7rem, 1.8vw, 0.95rem);
  color: var(--text-muted);
  margin-top: 0.15rem;
  font-weight: 600;
}

.hint {
  font-size: clamp(0.6rem, 1.4vw, 0.75rem);
  color: var(--accent-teal);
  margin-top: 0.2rem;
  opacity: 0.7;
}

main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* Leaflet custom styles */
.leaflet-container {
  background: #1a1a2e;
  cursor: crosshair !important;
}

.leaflet-tile-pane {
  filter: brightness(0.85) saturate(0.7);
}

/* Click marker */
.click-marker {
  background: linear-gradient(135deg, var(--accent-red), var(--accent-gold));
  border-radius: 50% 50% 50% 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-45deg);
  box-shadow: 0 5px 20px rgba(230, 57, 70, 0.5);
  border: 3px solid rgba(255, 255, 255, 0.4);
  animation: markerDrop 0.3s ease-out;
}

@media (max-width: 600px) {
  .click-marker {
    width: 32px;
    height: 32px;
  }
}

@keyframes markerDrop {
  0% {
    transform: rotate(-45deg) translateY(-20px);
    opacity: 0;
  }
  100% {
    transform: rotate(-45deg) translateY(0);
    opacity: 1;
  }
}

.click-marker span {
  transform: rotate(45deg);
  font-size: 18px;
  font-weight: 700;
  color: white;
}

/* Answer marker - text label */
.answer-marker {
  background: rgba(21, 21, 31, 0.9);
  border-radius: 4px;
  padding: 2px 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--accent-teal);
  white-space: nowrap;
}

.answer-marker span {
  font-family: "Nunito", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-teal);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Cluster marker - shows most common answer */
.cluster-marker {
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-red));
  border-radius: 6px;
  padding: 4px 8px;
  box-shadow: 0 3px 12px rgba(230, 57, 70, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.3);
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.cluster-marker:hover {
  transform: scale(1.1);
}

.cluster-marker span {
  font-family: "Nunito", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Hide default markercluster styles */
.marker-cluster {
  background: none !important;
}

.marker-cluster div {
  background: none !important;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.25rem;
  max-width: 340px;
  width: 100%;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  transform: scale(1);
  transition: transform 0.2s ease;
}

.modal.hidden .modal-content {
  transform: scale(0.95);
}

.close-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
  padding: 0.25rem;
}

.close-btn:hover {
  color: var(--accent-red);
}

.modal-content h2 {
  font-family: "Archivo Black", sans-serif;
  font-size: 1.2rem;
  margin-bottom: 0.4rem;
  color: var(--accent-gold);
}

#modal-coords {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

#existing-answers {
  max-height: 100px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.no-answers {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.nearby-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.answer-chip {
  display: inline-block;
  background: linear-gradient(135deg, rgba(42, 157, 143, 0.2), rgba(38, 70, 83, 0.3));
  border: 1px solid var(--accent-teal);
  border-radius: 14px;
  padding: 0.35rem 0.7rem;
  margin: 0.15rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.answer-chip:hover {
  background: linear-gradient(135deg, rgba(42, 157, 143, 0.4), rgba(38, 70, 83, 0.5));
  transform: scale(1.05);
}

.answer-chip:active {
  transform: scale(0.98);
}

.add-section {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  position: relative;
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

#char-count {
  position: absolute;
  right: 8px;
  font-size: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
}

#answer-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.65rem 2.5rem 0.65rem 0.8rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  min-width: 0;
  width: 100%;
}

#answer-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 15px rgba(244, 162, 97, 0.2);
}

#answer-input::placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
}

#submit-btn {
  background: linear-gradient(135deg, var(--accent-red), var(--accent-gold));
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  color: white;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(230, 57, 70, 0.3);
}

#submit-btn:active {
  transform: translateY(0);
}

/* Verification overlay */
.verify-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.3s ease;
}

.verify-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.verify-content {
  text-align: center;
  padding: 2rem;
}

.verify-content h1 {
  font-family: "Archivo Black", sans-serif;
  font-size: 3rem;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--accent-red) 0%, var(--accent-gold) 50%, var(--accent-teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
}

.verify-content p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

#verify-turnstile {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

#verify-status {
  font-size: 0.85rem;
  color: var(--accent-teal);
}

/* Already submitted message */
.already-submitted {
  text-align: center;
  color: var(--accent-gold);
  font-size: 1rem;
  padding: 1rem;
  background: rgba(255, 193, 69, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(255, 193, 69, 0.2);
}

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaflet-popup-content {
  color: var(--text-primary);
  font-family: "Nunito", sans-serif;
  margin: 10px;
}

.leaflet-popup-tip {
  background: var(--bg-card);
}

.popup-answer {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-teal);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--accent-teal);
  border-radius: 3px;
}

/* Custom search control */
.leaflet-search-control {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 200px;
}

.leaflet-search-control input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: all 0.2s ease;
}

.leaflet-search-control input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 8px rgba(244, 162, 97, 0.3);
}

.leaflet-search-control input::placeholder {
  color: var(--text-muted);
  font-size: 12px;
}

.leaflet-search-control button {
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-gold));
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  color: white;
  font-family: "Archivo Black", sans-serif;
  font-size: 11px;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.leaflet-search-control button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(42, 157, 143, 0.4);
}

.leaflet-search-control button:active {
  transform: translateY(0);
}

/* Leaflet controls */
.leaflet-control-zoom {
  border: none !important;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 30px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--accent-teal) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 10, 15, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 9px !important;
  padding: 2px 5px !important;
}

.leaflet-control-attribution a {
  color: var(--accent-teal) !important;
}

/* Touch friendly for mobile */
@media (max-width: 600px) {
  .leaflet-search-control {
    min-width: 180px;
    padding: 6px;
  }

  .leaflet-search-control input {
    font-size: 14px;
    padding: 8px 10px;
  }

  .leaflet-search-control button {
    font-size: 12px;
    padding: 8px 12px;
  }

  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 34px !important;
    font-size: 18px !important;
  }

  .answer-marker span {
    font-size: 10px;
  }

  .cluster-marker span {
    font-size: 11px;
  }
}

/* Prevent rubber-banding on iOS */
@supports (-webkit-touch-callout: none) {
  html,
  body {
    height: -webkit-fill-available;
  }

  body {
    min-height: -webkit-fill-available;
  }

  /* Ensure map container has proper height on iOS */
  main {
    height: -webkit-fill-available;
  }

  #map {
    height: -webkit-fill-available;
    min-height: -webkit-fill-available;
  }
}
