:root{
  --bg:#0b1020;
  --bg-2:#0e1530;
  --card:#0f1a39cc;
  --stroke:#243167;
  --text:#d7e3ff;
  --muted:#8aa0d6;
  --accent:#4de2ff;
  --accent-2:#7a5cff;
  --danger:#ff4d6d;
  --shadow: 0 10px 30px rgba(0,0,0,.4);
  --radius:16px;
}
*{box-sizing:border-box}
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(1200px 700px at 80% -10%, #1a2a6cff, transparent 60%),
              radial-gradient(1000px 600px at -10% 120%, #162447ff, transparent 55%),
              var(--bg);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

body::before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  opacity:.25;
  mix-blend-mode:overlay;
  background-image: linear-gradient(var(--stroke) 1px, transparent 1px),
                    linear-gradient(90deg, var(--stroke) 1px, transparent 1px);
  background-size: 28px 28px;
  animation:gridShift 40s linear infinite;
}
@keyframes gridShift{ 0%{transform:translateY(0)} 100%{transform:translateY(28px)} }

#app {display:flex; flex-direction:column; height:100%; position:relative}
.topbar{
  display:flex; align-items:center; gap:14px; padding:10px 14px;
  border-bottom:1px solid #1f2b57;
  backdrop-filter: blur(10px);
  background: linear-gradient(180deg, #0e1737aa, #0a142faa);
  box-shadow: var(--shadow);
  position:relative; z-index:100;
  overflow-x:auto; overflow-y:hidden;
  flex-wrap:nowrap;
  white-space:nowrap;
  scrollbar-width:thin;
  scrollbar-color:#3a5a8a transparent;
}
.topbar::-webkit-scrollbar {
  height:6px;
}
.topbar::-webkit-scrollbar-track {
  background:transparent;
}
.topbar::-webkit-scrollbar-thumb {
  background:linear-gradient(90deg, #4a6a9a, #3a5a8a);
  border-radius:3px;
}
.topbar::-webkit-scrollbar-thumb:hover {
  background:linear-gradient(90deg, #5a7aaa, #4a6a9a);
}
.topbar > * {
  flex-shrink:0;
}
.brand{
  font-family: Orbitron, Inter, sans-serif;
  letter-spacing:.06em; font-weight:600;
  color:var(--text);
  display:flex; align-items:center; gap:10px;
  flex-shrink:0;
}
.chip{
  font-size:12px; padding:4px 8px;
  border:1px solid #2b3c7a; border-radius:999px;
  color:var(--muted);
}

#toolbar {
  display: flex; justify-content: space-between;
  gap: 20px; align-items:center; padding: 12px 16px;
  border-bottom: 1px solid #1b2650;
  background: linear-gradient(180deg, #0b143040, #0b143030);
  flex-wrap: wrap;
  position:relative; z-index:100;
}
.row {display:flex; gap:12px; align-items:center; flex-wrap:wrap}
.right {display:flex; gap:12px; align-items:center; flex-wrap:wrap}

.emoji-btn-group {
  display: flex; gap: 6px; align-items: center;
  flex-shrink: 0;
}

.emoji-btn {
  position: relative; width: 44px; height: 44px;
  border: 2px solid #2a3a7a; border-radius: 12px;
  background: linear-gradient(180deg, #0f1b3b, #0b142f);
  color: var(--text); font-size: 20px;
  cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 1px #213069 inset, 0 4px 12px #0008;
  opacity: 0.90;
}

.emoji-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 6px 16px #0008;
}

.emoji-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #0f2b4b, #0b1f3f);
  box-shadow: 0 0 0 2px var(--accent) inset, 0 0 20px rgba(77, 226, 255, 0.3);
}

.emoji-btn.active::after {
  content: ""; position: absolute; inset: -3px;
  border-radius: 14px; border: 2px solid var(--accent);
  opacity: 0.5; animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

/* More button dropdown for favorites overflow */
.more-btn-wrapper {
  position: relative;
  display: inline-block;
}

.more-btn {
  font-weight: bold;
  letter-spacing: 2px;
}

.more-dropdown {
  display: none;
  position: fixed;
  margin-top: 8px;
  background: rgba(14, 23, 55, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid #1f2b57;
  border-radius: 12px;
  padding: 6px;
  z-index: 10000;
  min-width: 50px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.more-dropdown.open {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.more-dropdown .emoji-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
}

.toolbar-section {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 13px; color: #d0d0d0; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
  opacity: 0.90;
}

.zoom-display {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 14px;
  font-weight: 600;
  color: #d0d0d0;
  opacity: 0.90;
  padding: 4px 10px;
  background: rgba(90, 106, 138, 0.15);
  border: 1px solid rgba(90, 106, 138, 0.3);
  border-radius: 8px;
  min-width: 50px;
  text-align: center;
}

select, input {
  appearance:none; color:var(--text);
  background: var(--card); border:1px solid #243167;
  outline:none; padding:10px 12px; border-radius:12px; min-height:40px;
  opacity: 0.90;
}
label {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  }
input[type="checkbox"]{
  appearance:auto; width:auto; height:auto; accent-color: var(--accent);
}

.btn {
  position:relative; border:1px solid #2a3a7a;
  background: linear-gradient(180deg, #0f1b3b, #0b142f);
  color:var(--text); padding:10px 14px;
  border-radius:14px; cursor:pointer; transition: .2s transform;
  box-shadow: 0 0 0 1px #213069 inset, 0 6px 20px #0008;
  opacity: 0.90;
}
.btn:hover{ transform: translateY(-1px); }
.btn::after{
  content:""; position:absolute; inset:-2px; border-radius:16px;
  background: radial-gradient(60% 60% at 50% -20%, #4de2ff55, transparent 60%),
              radial-gradient(60% 60% at 110% 120%, #7a5cff40, transparent 60%);
  filter: blur(8px); opacity:.6; z-index:-1;
}

#map {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  width:100%;
  height:100%;
  border-top:1px solid #1a2660; border-bottom:1px solid #1a2660;
  z-index:1;
}

.attribution {
  position:absolute; bottom:10px; right:10px;
  background: linear-gradient(180deg, #0d1634cc, #0a1530cc);
  padding:6px 10px; border:1px solid #22306a;
  border-radius:10px; font-size:12px; color:var(--muted);
  box-shadow: var(--shadow);
}

/* Export history tooltip: white text, no background/border */
.history-tooltip{
  color:#fff; background:transparent; border:none; box-shadow:none;
  font-weight:600; text-shadow:0 1px 2px rgba(0,0,0,.6);
}

/* Google Maps-style ruler - Dark theme adapted */

/* Segment labels: white pill, dark gray text, auto-resize */
.ruler-segment-label {
  display: inline-block;
  background: rgba(255, 255, 255, 0.97);
  color: #3c4043;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 100px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  letter-spacing: 0.01em;
  pointer-events: none;
  position: relative;
}

/* Total label: larger blue pill, bold white text, auto-resize */
.ruler-total-label {
  display: inline-block;
  background: #1a73e8;
  color: #fff;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 100px;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.5), 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  letter-spacing: 0.02em;
  pointer-events: none;
  position: relative;
}

/* Ensure label icons don't interfere */
.ruler-segment-icon, .ruler-total-icon {
  background: transparent !important;
  border: none !important;
}

/* Ruler point markers - draggable with animations */
.ruler-point-marker {
  background: transparent !important;
  border: none !important;
}

.ruler-point {
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.ruler-point:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.ruler-point.dragging {
  cursor: grabbing;
  transform: scale(1.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Pop animation for new points */
@keyframes rulerPointPop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.ruler-point.new {
  animation: rulerPointPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Label fade-in animation */
@keyframes rulerLabelFade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.ruler-segment-label.new,
.ruler-total-label.new {
  animation: rulerLabelFade 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.leaflet-marker-icon.ruler-point-marker:active {
  cursor: grabbing !important;
}
.leaflet-dragging .leaflet-marker-icon.ruler-point-marker {
  cursor: grabbing !important;
}

/* Loading screen to prevent flash before auth check */
#authLoading {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); z-index: 9999; overflow: hidden;
}

#particleCanvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}

.loading-content {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; z-index: 10;
}

.loading-logo {
  font-family: 'Orbitron', monospace; font-size: 3rem; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  background-clip: text; -webkit-background-clip: text; color: transparent;
  margin-bottom: 1rem; letter-spacing: 2px;
  animation: logoGlow 2s ease-in-out infinite alternate;
}

.loading-text {
  color: var(--muted); font-size: 1rem; opacity: 0.8;
  animation: fadeInOut 1.5s ease-in-out infinite alternate;
}

@keyframes logoGlow {
  0% { filter: drop-shadow(0 0 10px var(--accent)) brightness(1); }
  100% { filter: drop-shadow(0 0 20px var(--accent)) brightness(1.2); }
}

@keyframes fadeInOut {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* Stats modal styles */
.stats-modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); z-index: 1000; display: none;
  align-items: center; justify-content: center;
}
.stats-modal-content {
  background: var(--bg); border: 1px solid var(--stroke); border-radius: 12px;
  max-width: 600px; width: 90%; max-height: 80%; overflow-y: auto;
  box-shadow: var(--shadow);
}
.stats-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--stroke);
}
.stats-modal-body { padding: 20px; }
.limit-indicator {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--card); border-radius: 8px; margin: 4px 0;
}
.limit-bar {
  flex: 1; height: 6px; background: var(--stroke); border-radius: 3px;
  margin: 0 12px; overflow: hidden;
}
.limit-fill {
  height: 100%; border-radius: 3px; transition: width 0.3s ease;
}
.limit-fill.safe { background: var(--success); }
.limit-fill.warning { background: var(--warning); }
.limit-fill.danger { background: var(--danger); }

label{ font-size:13px; color:var(--muted); }
.divider{
  width:1px;
  height:22px;
  background:#22306a;
  margin:0 6px;
  align-self: center;
  flex-shrink: 0;
}
.glow-dot{ width:6px; height:6px; border-radius:50%;
  background:var(--accent); box-shadow:0 0 10px var(--accent);
  display:inline-block; margin-right:6px; }
/* Position side tools (ruler and box controls) lower, relative to toolbar */
.leaflet-top.leaflet-right {
  top: auto;
  bottom: auto;
  margin-top: 0;
}

/* Calculate toolbar height: topbar (~50px) + toolbar (~60px) = ~110px, add some spacing */
.leaflet-control-container .leaflet-top.leaflet-right {
  top: 120px !important;
}

/* Move zoom controls to bottom left */
.leaflet-control-zoom {
  position: fixed !important;
  bottom: 30px !important;
  left: 10px !important;
  top: auto !important;
}

@media (max-width: 900px){ }

/* Population Density Legend Bar */
.density-legend {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px 8px;
  background: rgba(15, 15, 25, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  min-width: 300px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.density-legend.visible { display: flex; }
.density-legend .info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  min-height: 28px;
}
.density-legend .default-title {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  width: 100%;
  text-align: center;
}
.density-legend .default-title.hidden { display: none; }
.density-legend .hover-info {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.density-legend .hover-info.visible { display: flex; }
.density-legend .area-info { display: flex; flex-direction: column; }
.density-legend .area-name {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.density-legend .area-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
}
.density-legend .density-value-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: #f0b866;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.density-legend .density-unit {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
}
.density-legend .bar-container {
  position: relative;
  width: 260px;
}
.density-legend .bar {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(to right,
    #fef9c3 0%,
    #fef08a 6%,
    #fcd34d 12%,
    #fbbf24 18%,
    #fb923c 30%,
    #f97316 45%,
    #dc2626 65%,
    #991b1b 82%,
    #7f1d1d 100%
  );
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}
.density-legend .marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 18px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(0,0,0,0.5), 0 0 0 2px rgba(255,255,255,0.3);
  transform: translateX(-50%);
  opacity: 0;
  transition: left 0.15s ease, opacity 0.15s ease;
}
.density-legend .marker.visible { opacity: 1; }
.density-legend .labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.5);
}

/* Logout button - red styling */
#logoutBtn {
  background: linear-gradient(180deg, #7f1d1d, #581c1c) !important;
  border-color: #991b1b !important;
  color: #fecaca !important;
}
#logoutBtn:hover {
  background: linear-gradient(180deg, #991b1b, #7f1d1d) !important;
  border-color: #dc2626 !important;
  transform: translateY(-1px);
}

/* Settings modal - wider to avoid horizontal scrollbar */
#userSettingsModal .stats-modal-content {
  max-width: 700px;
  width: 95%;
  overflow: hidden;
}

/* Modal content - no scrollbar here, only on body */
.stats-modal-content {
  overflow: hidden;
}

/* Modal body scrollbar styling - single scrollbar with dark blue theme */
.stats-modal-body {
  scrollbar-width: thin;
  scrollbar-color: #3a5a8a var(--bg-2);
  max-height: calc(80vh - 80px);
  overflow-y: auto;
}
.stats-modal-body::-webkit-scrollbar {
  width: 8px;
}
.stats-modal-body::-webkit-scrollbar-track {
  background: var(--bg-2);
  border-radius: 4px;
}
.stats-modal-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #4a6a9a, #3a5a8a);
  border-radius: 4px;
}
.stats-modal-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #5a7aaa, #4a6a9a);
}
